这是我的用例的低调版本。我有
用于转换的XSL文件
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<xsl:output method="text"/>
<xsl:template match="Message">
<xsl:for-each select="ent">
<xsl:variable name="current_key" select="@key"/>
<xsl:variable name="current_type" select="@type"/>
<xsl:variable name="Match" select="exsl:node-set(msg)/ent"/>
<xsl:copy>
<xsl:copy-of select="exsl:node-set($Match)/@type"/>
<xsl:copy-of select="exsl:node-set($Match)/@key|exsl:node-set($Match)/translation/text()"/>
<!--- <xsl:copy-of select="exsl:node-set($Match)/@key|exsl:node-set($Match)/translation/text()|exsl:node-set($Match)/@type"/> Trial statement -->
</xsl:copy>
</xsl:for-each>
<xsl:call-template name = "Me" select="$Message"/>
</xsl:template>
</xsl:stylesheet>
输入文件如下
<?xml version="1.0" encoding="utf-8"?>
<msg>
<ent key="key1" type="error">
<text>Error: Could not find </text>
<translation>Another Error similar to previous one.</translation>
</ent>
<ent key="key2" type="damage">
<text>Error2: Could not find2 </text>
<translation>Another Error2 similar to previous one.</translation>
</ent>
</msg>
我在Perl中使用libXSLT作为我的转换引擎。我的转换脚本已在此Bamboo Chart API中提及。每当我执行脚本时,我得到如下输出。
Error: Could not find
Another Error similar to previous one.
Error2: Could not find2
Another Error2 similar to previous one.
为什么属性type
没有被打印出来?如何借助exsl:node-set
或任何其他技术检索它?另外,我可以在试用语句中包含属性type
,使其位于输出中吗?
答案 0 :(得分:2)
以下样式表:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/msg">
<xsl:for-each select="ent">
<xsl:text>KEY: </xsl:text>
<xsl:value-of select="@key"/>
<xsl:text> TYPE: </xsl:text>
<xsl:value-of select="@type"/>
<xsl:text> TEXT: </xsl:text>
<xsl:value-of select="text"/>
<xsl:text> TRANSLATION: </xsl:text>
<xsl:value-of select="translation"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
应用于您的输入示例时,将生成:
KEY: key1
TYPE: error
TEXT: Error: Could not find
TRANSLATION: Another Error similar to previous one.
KEY: key2
TYPE: damage
TEXT: Error2: Could not find2
TRANSLATION: Another Error2 similar to previous one.