如何从全局参数读取输入文件,修改并发送到输出? [XSLT]
How to read input file from global parameter, modify and send it to output? [XSLT]
我应该在模板中写什么 "initial" 以从输入读取文件、从输入修改几个节点并将修改后的文件发送到输出?
这是一个示例:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs" xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="saxon"
version="2.0">
<xsl:output method="xml" indent="yes" media-type="text/xml" />
<xsl:param name="$input_file"/>
<xsl:param name="input" select="saxon:parse($input_file)"></xsl:param>
<xsl:template match="/" name="initial">
<xsl:result-document href="output.xml">
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
只需编写执行您想要进行的转换更改的模板,并将模板应用于所有已解析的节点:
<xsl:output method="xml" indent="yes" media-type="text/xml" />
<xsl:param name="input_xml" as="xs:string"><![CDATA[<root>
<foo>foo 1</foo>
<bar>bar 1</bar>
</root>]]></xsl:param>
<xsl:param name="input" select="saxon:parse($input_xml)"/>
<xsl:template match="/" name="initial">
<xsl:apply-templates select="$input/node()"/>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<foobar>
<xsl:apply-templates select="@* | node()"/>
</foobar>
</xsl:template>
</xsl:stylesheet>
如果你想要一个特定的输出文档,然后包装应用模板,例如
<xsl:output method="xml" indent="yes" media-type="text/xml" />
<xsl:param name="input_xml" as="xs:string"><![CDATA[<root>
<foo>foo 1</foo>
<bar>bar 1</bar>
</root>]]></xsl:param>
<xsl:param name="input" select="saxon:parse($input_xml)"/>
<xsl:template match="/" name="initial">
<xsl:result-document href="output.xml">
<xsl:apply-templates select="$input/node()"/>
</xsl:result-document>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<foobar>
<xsl:apply-templates select="@* | node()"/>
</foobar>
</xsl:template>
</xsl:stylesheet>
我应该在模板中写什么 "initial" 以从输入读取文件、从输入修改几个节点并将修改后的文件发送到输出?
这是一个示例:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs" xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="saxon"
version="2.0">
<xsl:output method="xml" indent="yes" media-type="text/xml" />
<xsl:param name="$input_file"/>
<xsl:param name="input" select="saxon:parse($input_file)"></xsl:param>
<xsl:template match="/" name="initial">
<xsl:result-document href="output.xml">
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
只需编写执行您想要进行的转换更改的模板,并将模板应用于所有已解析的节点:
<xsl:output method="xml" indent="yes" media-type="text/xml" />
<xsl:param name="input_xml" as="xs:string"><![CDATA[<root>
<foo>foo 1</foo>
<bar>bar 1</bar>
</root>]]></xsl:param>
<xsl:param name="input" select="saxon:parse($input_xml)"/>
<xsl:template match="/" name="initial">
<xsl:apply-templates select="$input/node()"/>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<foobar>
<xsl:apply-templates select="@* | node()"/>
</foobar>
</xsl:template>
</xsl:stylesheet>
如果你想要一个特定的输出文档,然后包装应用模板,例如
<xsl:output method="xml" indent="yes" media-type="text/xml" />
<xsl:param name="input_xml" as="xs:string"><![CDATA[<root>
<foo>foo 1</foo>
<bar>bar 1</bar>
</root>]]></xsl:param>
<xsl:param name="input" select="saxon:parse($input_xml)"/>
<xsl:template match="/" name="initial">
<xsl:result-document href="output.xml">
<xsl:apply-templates select="$input/node()"/>
</xsl:result-document>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<foobar>
<xsl:apply-templates select="@* | node()"/>
</foobar>
</xsl:template>
</xsl:stylesheet>