我想在使用XSL编码
的XML开头添加样式表标签输入XML:
<?xml version="1.0" encoding="UTF-8"?>
<LearningStandards>
<CoreStandardVersion>2.2</CoreStandardVersion>
</LearningStandards>
转换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>
输出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>
输出需要作为样式表标记,类型为text / xsl和href dita.xsl
预期输出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>
请帮助我。
答案 0 :(得分:1)
&#34; stylesheet标签&#34;你引用的实际上是一个处理指令。您可以使用xsl:processing-instruction
输出它,如下所示:
<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>