【问题标题】:XSLT - Hyphen in XML root elementXSLT - XML 根元素中的连字符
【发布时间】:2015-02-05 10:58:52
【问题描述】:

如果根元素中有连字符,XSLT 不会找到它:

<serial-issue>
    <title>hello</title>
    <issue-info>
        <pii>3426-4114(11)X6013-4</pii>
        <jid>Journal</jid>
        <issn>1526-4114</issn>
    </issue-info>
</serial-issue>

这是 XSLT 脚本:

<xsl:template match="/">
    <html>
        <body>
            <xsl:apply-templates select="serial-issue"/>
        </body>
    </html>
</xsl:template>

<xsl:template match="issue-info">
    <test>
    <xsl:value-of select="jid"/>
</test>
</xsl:template>

上面的脚本不工作。如果“serial-issue”更改为“serialissue”,它会起作用。你能帮忙吗?

【问题讨论】:

  • 要么提供的示例不正确,要么您有一个非常基本的 XSLT 解析器。这行不通……
  • 你有一个未声明的命名空间'ce'并且你的&lt;test&gt;节点没有关闭......
  • 不过,根节点的名称应该不是问题。一旦我上面提到的问题得到解决,我就可以毫无问题地进行转换(我使用的是 Visual Studio 2010)
  • 我已经进行了更改。我仍然无法完成这项工作。
  • 您使用什么作为处理器?你所说的“无法使这个工作”是什么意思?有什么错误吗?

标签: xml xslt


【解决方案1】:

在本例中,调用了一个匹配“serial-issue”的模板,但没有这样的模板。

添加

<xsl:template match="serial-issue">
        <xsl:apply-templates />
</xsl:template>

您的 XSL 脚本将解决问题。 此外,它不是 HTML 标记,因此它不会在输出中起作用。

样式表的最小版本可能如下所示:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
  <xsl:output method="html"/>

  <xsl:template match="/">
     <html><body>
        <xsl:apply-templates />
     </body></html>
  </xsl:template>

<xsl:template match="serial-issue">
        <xsl:apply-templates />
</xsl:template>

<xsl:template match="issue-info">
       <xsl:value-of select="jid"/>
</xsl:template>

</xsl:stylesheet>

【讨论】:

  • "将 ... 添加到您的 XSL 脚本将解决问题。" 不,它不会。
猜你喜欢
  • 1970-01-01
  • 2020-08-11
  • 2013-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-28
相关资源
最近更新 更多