web-dev-qa-db-fra.com

Transformer XML XSLT avec des espaces de noms

J'essaie de transformer certains [~ # ~] xml [~ # ~] en [~ # ~ ] html [~ # ~] en utilisant [~ # ~] xslt [~ # ~] .

Problème:

Je n'arrive pas à le faire marcher. Quelqu'un peut-il me dire ce que je fais mal?

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

Vous devez fournir un préfixe d'espace de noms dans votre xslt pour les éléments que vous transformez. Pour une raison quelconque (au moins dans un Java JAXP), vous ne pouvez pas simplement déclarer un espace de noms par défaut. Cela a fonctionné pour moi:

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

Cela interceptera tout ce qui est espacé dans votre doc XML.

57
Andy Gherna