【问题标题】:XSLT: Get the value of an attribute created dynamicallyXSLT:获取动态创建的属性的值
【发布时间】:2020-06-17 11:26:33
【问题描述】:

我是 XSLT 的新手,我正在尝试获取我刚刚创建的属性的内容。

我有一些 XML,如下所示:

<subpara id="subpara">
    <title>I am some heavy title</title>
        <para id="para">Here is some dummy text for a dummy para.</para>
            <table id="t01" tocentry="1">
            ...

在 XSLT 中,我这样做:

<xsl:template match="subpara/title">
    <div>
        <xsl:attribute name="class">
            <xsl:text>title</xsl:text>
            <xsl:call-template name="addChangeClasses"/>
        </xsl:attribute>

        <xsl:attribute name="data-numbering">
            <xsl:apply-templates select="parent::*" mode="numbering"/>
        </xsl:attribute>
        # HERE I'D LIKE TO HAVE THE CONTENT OF THE ATTRIBUTE I JUST CREATED
        <xsl:value-of select"@data-numbering"/>  

        <xsl:apply-templates/>
    </div>
</xsl:template>

我的意图是创建该输出:

<div class="title" data-numbering="1.1">1.1 - I am some heavy title</div>

所以我正在创建一个属性数据编号,但我想显示它的内容。 显然,&lt;xsl:value-of select="@data-numbering"/&gt; 是不对的。

有人可以帮助我吗?提前致谢 ! :)

【问题讨论】:

    标签: html xml xslt xpath


    【解决方案1】:

    没有看到你的模板返回什么我只是在这里做一个最好的猜测:

    <xsl:variable name="d_numb">
      <xsl:apply-templates select="parent::*" mode="numbering"/>
    </xsl:variable>
    
    <xsl:attribute name="data-numbering" select="$d_numb"/>
    
    <xsl:value-of select="$d_numb"/>
    

    因此,将模板返回的任何值存储在变量中。然后使用该变量填充属性并输出值。

    【讨论】:

    • 是的@Sebastien!这样可行!我刚刚使用了 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多