Question

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top