当前位置: 动力学知识库 > 问答 > 编程问答 >

xslt - how to fetch the value of one node based on the value from another node

问题描述:

I want to fetch the "index" value based on what is present in the string

<sch name="main">

<norm string="back-slash"/>

<norm string="open-braces" />

<norm string="close-braces" />

</sch>

<strings name="consts">

<string name="back-slash" val="\\" index="0"/>

<string name="close-braces" val="]" index="2"/>

<string name="remove-null" val="null" index="3" />

</strings>

i tried this but it doesnt' work. Can yuou please help?

<xsl:template match="norm" >

<xsl:variable name="$nme" select="@string"/>

<xsl:value-of select="/strings/@name=$nme/@index"/>,

</xsl:template>

网友答案:
/strings/@name=$nme/@index

is not valid XPath. You need an attribute selector if you wish to target a node by one of its attributes.

/strings/*[@name=$nme]/@index
网友答案:

First of all, the name of your variable $nme is not a valid Qname.

Instead of

<xsl:variable name="$nme" select="@string"/>

you should use

<xsl:variable name="nme" select="@string"/>

try this template:

<xsl:template match="norm" >
    <xsl:variable name="nme" select="@string"/>
    <xsl:value-of select="../following-sibling::strings/string[@name=$nme]/@index"/>,
</xsl:template>
分享给朋友:
您可能感兴趣的文章:
随机阅读: