我有各种方法来删除" $"在" statValue1"节点,没有运气。有人可以帮助我使用样式表。
如果您在下面看到一些源XML,我需要从所有statTitle1中删除$
<?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:stylesheet version="1.0" xmlns:xsl="w3.org/1999/XSL/Transform">
<xsl:output encoding="iso-8859-1" method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="translate(//tours/tour/years/year/stats/stat/details/plr[1]/statValues/statValue1, '*\%!@$&', '')"/>
</xsl:stylesheet>
答案 0 :(得分:0)
使用
<xsl:template match="statValues/statValue1">
<xsl:copy>
<xsl:value-of select="translate(., '$', '')"/>
</xsl:copy>
</xsl:template>
而不是你拥有的第二个模板。
答案 1 :(得分:0)
因为您对子元素使用了不同的名称,所以需要更加通用。
<xsl:template match="statValues">
<xsl:for-each select="*" >
<xsl:copy>
<xsl:value-of select="translate(., '$', '')"/>
</xsl:copy>
</xsl:for-each>
</xsl:template>