【发布时间】:2016-08-26 02:18:34
【问题描述】:
基本上,我有 3 个独立的 XSLT,目前可用于 3 个不同的 XML。相反,我希望有一个 XSLT,它可以根据传入的特定内容决定执行特定的 XSLT 并获得格式良好的 XML。
我尝试使用以下方法 -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:choose>
<xsl:when test="fruits/apples">
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<data>
<doc api_type="2" key="20" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:custom="urn:custom.com" ">
<custom:DataSet xyt1:type="tdc:somedataset">
<custom:some_table>
<custom:anothertable>
<xyt1:key>
<xyt1:fruitqty>
<xsl:value-of select="fruit/apple"/>
</xyt1:fruitqty>
</xyt1:key>
<end of this xslt>
</xsl:when>
<xsl:when test="vegetables/tomatoes">
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<data>
<doc api_type="3" key="100" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:custom="urn:custom.com" ">
<custom:DataSet xyt1:type="tdc:somedataset2">
<custom:some_table2>
<custom:anothertable2>
<xyt1:fruitqty>
<xsl:value-of select="fruit/oranges"/>
</xyt1:fruitqty>
<end of this xslt2>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
我会得到两个不同的 XML 文件,像这样 -
文件 1 -
<fruits>
<apple>2</apple>
</fruits>
文件 2 -
<vegetables>
<tomatoes>2</tomatoes>
</vegetables>
所以我想在找到水果/苹果时执行第一个 xslt,然后为蔬菜/西红柿执行另一个。
确切地说,基于输入 XML 节点,我想执行一个特定的 XSLT,我有单独的工作文件,但我希望所有这些都在一个 XSLT 中。
此方法进入正确的块内,但不输出任何“节点”,它只是输出 XML 内的值。
例如 .-
它只为苹果显示“2”,而不是像<xyt1:fruitqty> 2 </xyt1:fruitqty>.这样的节点
因此,我无法获得格式正确的 XML。任何想法如何做到这一点?
【问题讨论】:
标签: xml xslt xsd xml-parsing