XSLT自关闭关闭标签添加属性



我有一些文本,输入:

有两个共同感兴趣的<Q1/>候选目标<Q2/>:正确<Q3/>

预期输出:

有两个候选<xref ref-type="query" rid="Q0001"/>共同关心的目标<xref ref-type="query" rid="Q0002"/>:正确的<xref ref-type="query" rid="Q0003"/>

我试过下面的代码,它只返回<xref ref-type="query" rid="Q0001"/>

<xsl:template match="node()[starts-with(name(),'Q')]">
        <xref ref-type="query">
            <xsl:attribute name="rid">
                <xsl:text>Q</xsl:text><xsl:number format="0000" select="." level="any"/>
            </xsl:attribute>
        </xref>
    </xsl:template>

请帮忙提前致谢

这会以请求的格式生成rid属性:

<xsl:template match="node()[starts-with(name(),'Q')]">
    <xref ref-type="query">
         <xsl:attribute name="rid">
              <xsl:text>Q</xsl:text><xsl:number format="0001" value="substring-after(name(), 'Q')"/>
        </xsl:attribute>
    </xref>
</xsl:template>

最新更新