【问题标题】:xslt loop attribute fails with namespace atributesxslt 循环属性因命名空间属性而失败
【发布时间】:2018-11-18 18:12:20
【问题描述】:

我将属性转换为表格, 但我不知道会设置哪些属性, 所以我得到了以下解决方案:

                <simpletable  spectitle="Chapter Attribute">
                    <sthead>
                        <stentry>Name</stentry>
                        <stentry>Wert</stentry>
                    </sthead>
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates select="Head/@*"/>
                </simpletable>

<!-- ********************* Chapter Attribute -> simpleTable....strow ************************************************************************************** -->
<xsl:template match="Chapter/@*|Head/@*">
    <xsl:choose>
        <xsl:when test="string(.)">
            <strow>
                <stentry>
                    <xsl:value-of select="local-name(.)"/>
                </stentry>
                <stentry>
                    <xsl:value-of select="."/>
                </stentry>
            </strow>
        </xsl:when>
    </xsl:choose>
</xsl:template>

这是我要处理的 XML:

<Chapter title="Information" termpool="" nodeid="DE-123" xmltag="Chapter" 
 status="" id="" language="" version="">
<Head UniqueID="DE-234" xmlns:axf="http://www.antennahouse.com/names
         /XSL/Extensions">Information</Head>

这是结果

<strow>
    <stentry>title</stentry>
    <stentry>Information</stentry>
</strow>
<strow>
    <stentry>nodeid</stentry>
    <stentry>DE-123</stentry>
</strow>
<strow>
    <stentry>xmltag</stentry>
    <stentry>Chapter</stentry>
</strow>
<strow>
    <stentry>UniqueID</stentry>
    <stentry>DE-234</stentry>
</strow>

对于 > 它工作正常,但对于 > 它不识别 xmlns:axf (或者 xmlns:axf 有一个值集)

希望有人给我一个提示,如何使用 @* 访问 xmlns:axf 谢谢乔辰

【问题讨论】:

    标签: loops xslt namespaces attributes


    【解决方案1】:

    在 XPath 使用的 XDM 数据模型中,名称空间和属性是完全不同的东西。属性轴@* 为您提供属性,对于您需要的名称空间轴namespace::*

    请注意,这将为您提供元素范围内的所有命名空间,而不仅仅是在该元素上声明的命名空间。如果您确实想要元素上存在而父元素上不存在的命名空间,则逻辑将取决于您使用的 XSLT 版本,而您尚未告诉我们。

    【讨论】:

    • 感谢您的回答,但出现错误。我使用 2.0 版。我试过了
    • 感谢您的回答,但出现错误。我使用 2.0 版。我尝试了 ,它们都在执行时失败了。
    • 我的 xmlspy 说关于 xpath,命名空间 xmlns 是未定义的,实际上,它没有在我的 xml 的 tge 顶部声明,也许这会导致问题:
    • 我告诉过你使用namespace::*,那你为什么要使用xmlns::@*namespace::@*?此外,请不要在没有先阅读参考书的情况下输入您在 SO 答案中找到的代码,以便您了解它的实际含义。
    猜你喜欢
    • 1970-01-01
    • 2011-11-08
    • 2010-10-27
    • 2016-01-20
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多