Right now I have an xml database with all of my products, but I wish to pull each one out individually into it's own xml file. Right now I can do this, but the problem I am having is that I need to declare a new xsl stylesheet after the transformation.

I have tried my best and looked over questions for hours, but still no luck. If anyone is able to help me out, that would be great.

有帮助吗?

解决方案

You could output a new xml-stylesheet processing instruction.

Example...

XML Input

<?xml-stylesheet type="text/xsl" href="orig.xsl"?>
<doc>
    <test/>
</doc>

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="processing-instruction()[name()='xml-stylesheet']">
        <xsl:processing-instruction name="xml-stylesheet">
            <xsl:text> type="text/xsl" href="new.xsl"</xsl:text>
        </xsl:processing-instruction>       
    </xsl:template>

</xsl:stylesheet>

XML Output

<?xml-stylesheet type="text/xsl" href="new.xsl"?>
<doc>
    <test/>
</doc>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top