Domanda

I'm calling in XML using document(). I need to transform the imported XML. Is this possible?

<xsl:copy-of select="document('C:\my.xml')/*"/> 
<xsl:apply-templates/>

Thanks!

È stato utile?

Soluzione

Use <xsl:apply-templates select="document('file:///c:/my.xml')/*"/>, then you only need to add templates for the nodes in the file.

Altri suggerimenti

For example, a my.xml is given below

<?xml version="1.0" standalone="no"?>
<root>
    <a>XXX</a>
    <b>YYY</b>
</root>

and the current xml is given below:

<?xml version="1.0" encoding="UTF-8"?>
<root_test>
    <test1>123</test1>
    <test2>456</test2>
</root_test>

when the following stylesheet is applied:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:template match="root_test">
        <xsl:copy>
            <xsl:apply-templates/>
            <xsl:apply-templates select="document('my.xml')/*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="a[document('my.xml')]">
        <success><xsl:apply-templates/></success>
    </xsl:template>

</xsl:stylesheet>

it outputs

<?xml version="1.0" encoding="utf-8"?>
<root_test>
    123
    456

    <success>XXX</success>
    YYY
</root_test>

notice that the templates for node a in my.xml has been applied.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top