0
votes

I want to add style-sheet tag at starting of the XML using XSL coding

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<LearningStandards>
<CoreStandardVersion>2.2</CoreStandardVersion>
</LearningStandards>

Transformation XSLT:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output doctype-system="topic.dtd" indent="yes" method="xml"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="LearningStandards">
<topic id="x1" xml:lang="en-US" outputclass="AASS-DITA">
<title/>
<body>
<p>
<xsl:apply-templates/>
</p>
</body>
</topic>
</xsl:template>
<xsl:template match="CoreStandardVersion"/>

</xsl:stylesheet>

Output XML

<?xml version="1.0" encoding="UTF-8"?>
<topic id="x1" xml:lang="en-US" outputclass="AASS-DITA">
<title/>
<body>
<p>
<xsl:apply-templates/>
</p>
</body>
</topic>

Output needed as stylesheet tag with type text/xsl and href dita.xsl

Expected output XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="DITA.xsl"?>
<topic id="x1" xml:lang="en-US" outputclass="AASS-DITA">
<title/>
<body>
<p>Demonstrate command of the conventions of standard.</p>
</body>
</topic>

Please assist me.

1
Do you really mean to have <xsl:apply-templates/> in the middle of your expected and actual XML, or was this a typo in your question? Thanks!Tim C
Its copied mistakenly edited the questionUser515

1 Answers

1
votes

The "stylesheet tag" to which you refer is actually a processing instruction. You can use xsl:processing-instruction to output it, as follows:

<xsl:template match="LearningStandards">
    <xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="DITA.xsl"</xsl:processing-instruction>
    <topic id="x1" xml:lang="en-US" outputclass="AASS-DITA">
        <title/>
        <body>
            <p>
                <xsl:apply-templates/>
            </p>
        </body>
    </topic>
</xsl:template>