exsl:node-设置不检索属性值
exsl:node-set not retrieving attribute's value
这是我的用例的简化版本。我有
用于转换的 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 作为我的转换引擎。这个里面已经提到了我的转换脚本。每当我执行脚本时,我都会得到如下输出。
Error: Could not find
Another Error similar to previous one.
Error2: Could not find2
Another Error2 similar to previous one.
为什么属性 type
没有被打印出来?如何借助 exsl:node-set
或任何其他技术检索它?另外,我能否在 trial 语句中包含属性 type
,使其出现在输出中?
以下样式表:
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.
这是我的用例的简化版本。我有
用于转换的 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 作为我的转换引擎。这个
Error: Could not find
Another Error similar to previous one.
Error2: Could not find2
Another Error2 similar to previous one.
为什么属性 type
没有被打印出来?如何借助 exsl:node-set
或任何其他技术检索它?另外,我能否在 trial 语句中包含属性 type
,使其出现在输出中?
以下样式表:
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.