2011-08-05 20 views
-1

ここでは本当に奇妙な問題が発生しました。次のxmlファイルのノード値を取得できませんでした。誰も私のxsltファイルまたはxmlファイルで何が問題なのか教えていただけますか?私は他のxmlファイルでxsltの作業をすることができ、それは本当に簡単です。だから私はここで失われてしまう。 xmlファイルはXSLTでノード値を取得できませんでした

<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&amp;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ファイル

<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> 

が、XSLTファイルだけに/データ/学生/名前/ @ 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> 

答えて

0
XPathを変更すると、次のXMLファイルで動作します

XSLTは、最初のXMLファイルの名前空間を尊重しません。

2番目のXMLファイルには何もありません。

名前空間宣言を追加してXSLTを修正し、定義した名前空間接頭辞を使用するようにXPath式を変更します。したがって

xmlns:myprefix="http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0" 

...

/myprefix:catalog/myprefix:dataset/myprefix:access/@serviceName 
+0

おかげで返信のために多くのことを、あなたは、XPathで名前空間接頭辞を使用する方法の例を与えることができますか? – user851380

+0

私はどの名前空間を追加すべきですか?これです? – user851380

+0

xmlns = "http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0" – user851380

関連する問題