couldn't get node value in XSLT
I got this really odd problem here. I couldn't get t开发者_StackOverflowhe node value of the following xml file. Can anyone tell me what's wrong with my xslt file or xml file? cause I can have the xslt work on other xml file and it's really simple. So I am quit lost here. xml file
<catalog xmlns="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0" xmlns:xlink="http://www.w3.org/1999/xlink" name="Test Data">
<service name="tss" serviceType="OpenDAP" base="http://virbo.org/metamag/viewDataFile.jsp?filetype=data&docname="/>
<dataset name="Scalar">
<access serviceName="tss" urlPath="597C7956-742D-FEC6-D151-A37A7176E867"/>
<documentation type="summary">Single variable time series</documentation>
</dataset>
<dataset name="Structure">
<access serviceName="tss" urlPath="E981F1AF-EF4A-11FB-AFB6-F20218B07783"/>
<documentation type="summary">Vector (three component) time series</documentation>
</dataset>
<dataset name="Sequence">
<access serviceName="tss" urlPath="64C78182-9BDC-CBC4-56C5-679808F51398"/>
<documentation type="summary">Spectrum time series</documentation>
</dataset>
</catalog>
xslt file
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<h2>database</h2>
<li>
<xsl:for-each select="/catalog/dataset/access/@serviceName">
<xsl:value-of select="."/>
</xsl:for-each>
</li>
</xsl:template>
</xsl:stylesheet>
but the xslt file works on the following xml file with just change the xpath to /data/student/name/@id
<data class="grade2">
<student id="test1">
<name id="1">Bitu Kumar</name>
<course>MCA</course>
<sem>6</sem>
<marks>80</marks>
</student>
<student id="test2">
<name id="2">Santosh Kumar</name>
<course>MCA</course>
<sem>5</sem>
<marks>70</marks>
</student>
<student id="test3">
<name id="3">Ashish</name>
<course>M.Sc.</course>
<sem>4</sem>
<marks>80</marks>
</student>
<student id="test4">
<name id="4">Mahesh</name>
<course>MA</course>
<sem>3</sem>
<marks>80</marks>
</student>
</data>
Your XSLT does not respect the namespaces in your first XML file.
You second XML file doesn't have any.
Fix your XSLT by adding a namespace declaration, and change your XPath expression so that it uses whatever namespace prefix you define.
Thus:
xmlns:myprefix="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0"
...
/myprefix:catalog/myprefix:dataset/myprefix:access/@serviceName
精彩评论