Xml XSLT枚举映射
使用xsl将一个xml转换为另一个xml模式 如何将一个xml的枚举映射到另一个xml 例如: xsd 1: 输出xml:Xml XSLT枚举映射,xml,xslt,xsd,Xml,Xslt,Xsd,使用xsl将一个xml转换为另一个xml模式 如何将一个xml的枚举映射到另一个xml 例如: xsd 1: 输出xml: <Hindi>Tea</Hindi> 茶 我希望您只使用两种语言,否则我的代码将无法工作。我只是快速编写了代码,所以它可能不是最花哨的代码。请记住,条目必须具有相同的顺序。因此,如果要翻译枚举中位置x上的单词,x也必须是该单词在其他枚举中的位置 字典变量: <xsl:variable name="dict"> <eleme
<Hindi>Tea</Hindi>
茶
我希望您只使用两种语言,否则我的代码将无法工作。我只是快速编写了代码,所以它可能不是最花哨的代码。请记住,条目必须具有相同的顺序。因此,如果要翻译枚举中位置x上的单词,x也必须是该单词在其他枚举中的位置
字典变量:
<xsl:variable name="dict">
<element name="Hindi">
<simpleType>
<restriction base="xsd:string">
<enumeration value="Inp1" />
<enumeration value="Inp2" />
</restriction>
</simpleType>
</element>
<element name="English">
<simpleType>
<restriction base="xsd:string">
<enumeration value="Bread1" />
<enumeration value="Bread2" />
</restriction>
</simpleType>
</element>
</xsl:variable>
匹配模板:
<!-- This will match on every node with a specified element/@name in the dictionary -->
<xsl:template match="*[name() = $dict/element/@name]">
<xsl:variable name="fromLanguage" select="name()"/>
<xsl:variable name="wordToTranslate" select="."/>
<!-- My translation requires the same order of enumerations in order to do it correctly -->
<!-- I am counting the preceding siblings, so we can take the xth element of the other dictionary -->
<xsl:variable name="precSiblings" select="$dict/element[@name = $fromLanguage]//enumeration[@value = $wordToTranslate][1]/count(preceding-sibling::*)"/>
<!-- Renaming the language node -->
<xsl:element name="{$dict/element[@name != $fromLanguage]/@name}">
<xsl:value-of select="$dict/element[@name != $fromLanguage]//enumeration[$precSiblings + 1]/@value"/>
</xsl:element>
</xsl:template>
通过使用
xsl:when
<English>
<xsl:choose>
<xsl:when test="Hindi = 'Chay'">Tea</xsl:when>
<xsl:when test="Hindi = 'Roti'">Bread</xsl:when>
</xsl:choose>
<English>
茶叶
面包
您的问题不清楚。您是否在询问如何编写将执行两个转换(元素名和字符串内容)的XSLT另外,请说明是否使用XSLT 1.0或2.0。@michael.hor257k yes您是对的。。元素印地语-->英语和字符串内容映射Chay-->Tea和Roti-->Bread@michael.hor257k我更新了我的问题元素名称,这并不麻烦。我只想映射bot xsd的枚举。或者我们可以说,如果Chay在第一个xsd中被选中,我需要用相同的Tea替换RotiI。恐怕这不能回答我的问题。我更新了我的问题元素名称,这并不麻烦。我只想映射枚举。或者我们可以说,如果Chay在第一个xsd中被选中,我需要用同样的茶替换RotiSo,这对你有用吗?如果要保持相同的元素名称,可以将替换为。这将复制匹配模板中考虑的当前输入元素。
<xsl:variable name="dict">
<element name="Hindi">
<simpleType>
<restriction base="xsd:string">
<enumeration value="Inp1" />
<enumeration value="Inp2" />
</restriction>
</simpleType>
</element>
<element name="English">
<simpleType>
<restriction base="xsd:string">
<enumeration value="Bread1" />
<enumeration value="Bread2" />
</restriction>
</simpleType>
</element>
</xsl:variable>
<!-- This will match on every node with a specified element/@name in the dictionary -->
<xsl:template match="*[name() = $dict/element/@name]">
<xsl:variable name="fromLanguage" select="name()"/>
<xsl:variable name="wordToTranslate" select="."/>
<!-- My translation requires the same order of enumerations in order to do it correctly -->
<!-- I am counting the preceding siblings, so we can take the xth element of the other dictionary -->
<xsl:variable name="precSiblings" select="$dict/element[@name = $fromLanguage]//enumeration[@value = $wordToTranslate][1]/count(preceding-sibling::*)"/>
<!-- Renaming the language node -->
<xsl:element name="{$dict/element[@name != $fromLanguage]/@name}">
<xsl:value-of select="$dict/element[@name != $fromLanguage]//enumeration[$precSiblings + 1]/@value"/>
</xsl:element>
</xsl:template>
<English>
<xsl:choose>
<xsl:when test="Hindi = 'Chay'">Tea</xsl:when>
<xsl:when test="Hindi = 'Roti'">Bread</xsl:when>
</xsl:choose>
<English>