簡體   English   中英

如何使用 XSLT 從屬性值(在 XML 中)中刪除美元符號($)

[英]How to remove Dollar sign($) from Attribute's Value (in XML) using XSLT

我有以下 XML 文件,其中 $ 符號在屬性值中可用:

     <data>
        <DWFOutput>
           <FormsXML>
              <print name="_Print">
                 <ExportDocument docType="PDF">
                    <ExportSection name="MD0001B1014" BinNum="0" >
                       <dataElement name=" Period" value="$Annual" />
                       <dataElement name="Effective" value="$55" />
                    </ExportSection>
                    <ExportSection name="VZ400030798" BinNum="0">
                       <dataElement name="CityS" value="$213" />
                       <dataElement name="Zip 13" value="$50" />
                    </ExportSection>
                    <ExportSection name="VZ00040798" BinNum="0" >
                       <dataElement name="DCT_JOBNAMES" value="$ ABCD" />
                       <dataElement name="Policy Number" value="$ 2504"  />
                       <dataElement name="States" value="CA  AL  " />
                    </ExportSection>
                 </ExportDocument>
              </print>
           </FormsXML>
        </DWFOutput>
     </data>

按照預期,需要使用 XSLT 代碼來刪除“$”符號,所以我在 XSLT 代碼下面創建了相同的代碼,但是沒有得到預期的響應(即 $ 符號沒有被刪除)。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
   <xsl:template match="node()|@*">
           <xsl:copy>
              <xsl:apply-templates select="node()|@*"/>
           </xsl:copy>
       </xsl:template>
       <xsl:template match="/data/DWFOutput/FormsXML/print/ExportDocument/" > 
    <xsl:for-each select="ExportSection/dataElement">
            <xsl:variable name="RemoveDollar" select="@value"/>
                 <!--<xsl:value-of select="substring-after(.,'$dollar')"/>--> 
                <xsl:value-of select="translate($RemoveDollar,'$','')"/>
    </xsl:for-each>
   </xsl:template>

</xsl:stylesheet> 我是 XSLT 的初學者,所以有人可以在這里幫助我。 提前致謝!

需要使用 XSLT 代碼去除“$”符號

如果這就是您需要做的所有事情,那么請執行以下操作:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="@value">
    <xsl:attribute name="value">
        <xsl:value-of select="translate(., '$', '')"/>
    </xsl:attribute>
</xsl:template>

</xsl:stylesheet>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM