删除“$&引用;在xml中使用样式表

删除“$&引用;在xml中使用样式表,xml,xslt,translate,Xml,Xslt,Translate,我有各种各样的方法删除“statValue1”节点下的“$”,但没有运气。谁能帮我拿一下这张床单吗 如果您在下面看到一些源XML,我需要从所有Statitle1中删除$ <?xml-stylesheet type="text/xsl" href="file:///C:/Users/davidhe/Documents/Altova/XMLSpy2016/Examples/stats.xml"?> <tours> <tour tourCodeLC="s" tou

我有各种各样的方法删除“statValue1”节点下的“$”,但没有运气。谁能帮我拿一下这张床单吗

如果您在下面看到一些源XML,我需要从所有Statitle1中删除$

<?xml-stylesheet type="text/xsl" href="file:///C:/Users/davidhe/Documents/Altova/XMLSpy2016/Examples/stats.xml"?>
<tours>
    <tour tourCodeLC="s" tourCodeUC="S" tourName="Group!A>
        <years>
            <year year="2016">
                <lastTrnProc trnName="Through Week Ending: 02/29/2016" permNum="000" trnNum="032" endDate="Feb 28, 2016"/>
                <stats>
                    <stat statID="109" cat="1" rndOrEvt="Events">
                        <statName>Money List</statName>
                        <explanation>
The total official money a player has earned year-to-date. (109)
</explanation>
                        <tourAvg>$51,906</tourAvg>
                        <statTitles numOfStatTitles="3">
                            <statTitle1>Money</statTitle1>
                            <statTitle2/>
                            <statTitle3>YTD Victories</statTitle3>
                            <statTitle4/>
                            <statTitle5>Money Behind Lead</statTitle5>
                        </statTitles>
                        <details>
                            <plr plrNum="01666">
                                <plrName>
                                    <last>Smith</last>
                                    <first>Brad</first>
                                    <middle/>
                                    <nickname/>
                                </plrName>
                                <statValues>
                                    <rndEvents>3</rndEvents>
                                    <statValue1>
                                        $333,850</statValue1>
                                    <statValue2/>
                                    <statValue3>1</statValue3>
                                    <statValue4/>
                                    <statValue5/>
                                </statValues>
                                <curRank tied="">1</curRank>
                                <prevRank tied="">1</prevRank>
                            </plr>

使用



而不是第二个模板。

因为子元素使用不同的名称,所以需要更通用一些

<xsl:template match="statValues">
  <xsl:for-each select="*" >
  <xsl:copy>
    <xsl:value-of select="translate(., '$', '')"/>
  </xsl:copy>
  </xsl:for-each>
</xsl:template>


使用
start-with()
substring()
的组合。请记住xslt中的第一个字符有索引1,而不是0。这就是我所拥有的。。。您应该使用
match=“statValues/*”
instead@MatthewWhited,你是对的,我在评论中迷失了方向,选择了错误的模式,现在纠正了。也许我有这个错误,但这是我所拥有的,它仍然不起作用。Matt,谢谢你的帮助…看起来我快到了,但是新的样式表正在删除“statValues”节点。。。
<xsl:template match="statValues/st‌​atValue1">
  <xsl:copy>
    <xsl:value-of select="translate(., '$', '')"/>
  </xsl:copy>
</xsl:template>
<xsl:template match="statValues">
  <xsl:for-each select="*" >
  <xsl:copy>
    <xsl:value-of select="translate(., '$', '')"/>
  </xsl:copy>
  </xsl:for-each>
</xsl:template>