下一个问题:我有“InputDoc”xml 文档和 xslt 文件,以便转换为其他“OutputDoc”xml 文档。您可以在下面找到示例 xslt 和 xml 文档。
<?xml version="1.0" encoding="UTF-8"?>
<InputDoc>
<InputCollection>
<InputItem>
<InputValue>Value_1</InputValue>
</InputItem>
</InputCollection>
</InputDoc>
<?xml version="1.0" encoding="utf-16"?>
<OutputDoc>
<OutputElement>
<OutputItem>
<OutputValue>Value_1</OutputValue>
</OutputItem>
<OutputDescription>Description_1</OutputDescription>
</OutputElement>
</OutputDoc>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="//InputCollection">
<OutputDoc>
<xsl:for-each select="InputItem">
<OutputElement>
<OutputItem>
<OutputValue><xsl:value-of select="InputValue" /></OutputValue>
</OutputItem>
<OutputDescription>
<xsl:call-template name="InputValue2OutputDescriptionMappings">
<xsl:with-param name="InputValueParam" select="InputValue" />
</xsl:call-template>
</OutputDescription>
</OutputElement>
</xsl:for-each>
</OutputDoc>
</xsl:template>
<xsl:template name="InputValue2OutputDescriptionMappings">
<xsl:param name="InputValueParam" />
<xsl:choose>
<xsl:when test="$InputValueParam='Value_1'">Description_1</xsl:when>
<xsl:when test="$InputValueParam='Value_2'">Description_2</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
有用。但是,如果输出 xml 文档仅包含“OutputElement”节点,该节点包含“InputValue2OutputDescriptionMappings”中的值,即如果“OutputDescription”节点的值为空,那么“OutputElement”节点将不会包含在“OutputDoc”中。
我如何使用上面的 XSL 转换来做到这一点?