Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

confused about xsl and selectsinglenode

Status
Not open for further replies.

jlindahl

Programmer
Sep 23, 2003
46
0
0
US
i know i need a default namespace or something, but i am getting confused reading all posts and faq's. please help. below is my xml and xsl and asp. the asp page sends a selectsinglenode to search for and returns nothing. i saw a post about this in the faq's but i get confused about namespaces and the 'what-nots'.
Code:
<?xml version="1.0" standalone="yes"?>
<jobops>
  <job id="1">
    <position>position title</position>
    <jobid>1</jobid>
    <link>jobdesc.asp?jobid=1</link>
    <description>job description</description>
  </job>
  <job id="2">
    <position>position title 2</position>
    <jobid>2</jobid>
    <link>jobdesc.asp?jobid=2</link>
    <description>job description 2</description>
  </job>
</jobops>


<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/TR/WD-xsl">[/URL]
<xsl:template match="/">
  <table border="0">
    <xsl:for-each select="jobops/job">
      <tr>
        <td><P><xsl:value-of select="description"/></P></td>
      </tr>
	<tr>
	  	<td><br></br></td>
	</tr>
    </xsl:for-each>
  </table>
</xsl:template>

</xsl:stylesheet>

---asp code-----
Dim objXML
Dim objXSL
Dim strHTML
Dim objNode

'Load the XML File
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.load(Server.MapPath("xmlxsl.xml"))

'Get the XML record that you wish to view by calling the SelectSingleNode method and passing in the jobID of the job.
Set objNode = objXML.SelectSingleNode("jobops/job[@id = '1']")

'Load the XSL File
Set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = False
objXSL.load(Server.MapPath("xmlxsl_desc.xsl"))


' Transform the XML file using the XSL stylesheet
strHTML = objNode.transformNode(objXSL)

Set objXML = Nothing
Set objXSL = Nothing

' Spit out the resulting HTML... the data comes from the
' .xml file, but the formatting of the results depends
' completely upon the .xsl file.
Response.Write strHTML
 
Nothing to do with namespaces here - you not using any. The selectsinglenode is working fine too. The problem is with your stylesheet and the transformNode method.

First up, you're using the old stylesheet namespace. Secondly, I've never used transformNode myself but it appears that because you have selected a child node with the selectsinglenode method, this does not become the root node (you can't use match="/"). Also your <xsl:for-each select="jobops/job"> is wrong, because the 'root' is job. So change your stylesheet to:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="job">
    <table border="0">
        <tr>
          <td>
            <p>
              <xsl:value-of select="description"/>
            </p>
          </td>
        </tr>
        <tr>
          <td>
            <br/>
          </td>
        </tr>
    </table>
  </xsl:template>
</xsl:stylesheet>
and it should be fine.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top