XSLT Transform XML with Namespaces

后端 未结 2 992

I\'m trying to transform some XML into HTML using XSLT.

Problem:

I can\'t get it to work. Can someone tell me wh

相关标签:
2条回答
  • 2020-12-01 01:45

    How do you execute the transformation? Maybe you forgot to link the XSLT stylesheet to XML document using:

    <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
    

    at the beginning of XML document. More explanation here.

    0 讨论(0)
  • 2020-12-01 02:06

    You need to provide a namespace prefix in your xslt for the elements you are transforming. For some reason (at least in a Java JAXP parser) you can't simply declare a default namespace. This worked for me:

    <xsl:stylesheet version="1.0" xmlns:t="http://www.test.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xslFormatting="urn:xslFormatting">
    
        <xsl:output method="html" indent="no"/>
    
        <xsl:template match="/t:ArrayOfBrokerage">
            <xsl:for-each select="t:Brokerage">
                Test
            </xsl:for-each>
        </xsl:template>
    
    </xsl:stylesheet>
    

    This will catch everything that is namespaced in your XML doc.

    0 讨论(0)
提交回复
热议问题