XSLT Transform doesn't work until I remove root node

后端 未结 1 1012
死守一世寂寞
死守一世寂寞 2020-11-21 06:53

I\'m trying to extract the headline from the below XML from the Met Office web service using XSLT, however my XSLT select returns blank.

SOURCE:

<         


        
相关标签:
1条回答
  • 2020-11-21 07:21

    The problem: your XML puts its elements in a namespace.

    Solution: declare the same namespace in your stylesheet, assign it a prefix and use that prefix to address the elements in the source XML:

    XSLT 1.0

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:met="www.metoffice.gov.uk/xml/metoRegionalFcst"
    exclude-result-prefixes="met">
    <xsl:template match="/">
      <html>
      <body>
       <xsl:value-of select="met:RegionalFcst/met:FcstPeriods/met:Period/met:Paragraph[@title='Headline:']"/>
      </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
    
    0 讨论(0)
提交回复
热议问题