XSLT Transform XML with Namespaces

Mam jakiś XML, który próbuję przekształcić w HTML za pomocą XSLT, ale nie mogę go uruchomić na całe moje życie. Czy ktoś może mi powiedzieć, co robię źle?

XML

<ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.test.com/">
    <Brokerage>
        <BrokerageID>91</BrokerageID>
        <LastYodleeUpdate>0001-01-01T00:00:00</LastYodleeUpdate>
        <Name>E*TRADE</Name>
        <Validation i:nil="true" />
        <Username>PersonalTradingTesting</Username>
    </Brokerage>
</ArrayOfBrokerage>

XSLT

<xsl:stylesheet version="1.0" xmlns="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="/ArrayOfBrokerage">
        <xsl:for-each select="Brokerage">
            Test
       </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>
Author: Ethan Furman, 2009-11-13

2 answers

Musisz podać prefiks przestrzeni nazw w xslt dla elementów, które przekształcasz. Z jakiegoś powodu (przynajmniej w Java jaxp parser) nie można po prostu zadeklarować domyślnej przestrzeni nazw. To mi się udało:

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

To wychwyci wszystko, co jest przestrzenią nazw w Twoim dokumencie XML.

 53
Author: Andy Gherna,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-15 01:14:57

Jak wykonać transformację? Może zapomniałeś połączyć arkusz stylów XSLT z dokumentem XML używając:

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

Na początku dokumentu XML. więcej wyjaśnień tutaj .

 -2
Author: Steve,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-18 14:22:24