XSLT replace value

后端 未结 1 1135
情话喂你
情话喂你 2020-12-31 09:24

I have an XML like this



   

        
相关标签:
1条回答
  • 2020-12-31 09:55

    Basically you want an identity transform, with override rules.

    The following transform

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="PrintDollarsAndCents/text()[.='X']">Y</xsl:template>
    
    </xsl:stylesheet>
    

    applied to your input, produces the result:

    <OMDefault xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <PrintDollarsAndCents>Y</PrintDollarsAndCents>
       <MailAddrLine1>Add1</MailAddrLine1>
       <MailAddrLine2>Add2</MailAddrLine2>
    </OMDefault>
    

    The first template is an identity transform, which copies the input document exactly.

    The second template overrides text nodes with a value of X that are children of a PrintDollarsAndCents template. Note that it emits the value Y instead of its actual content.

    0 讨论(0)
提交回复
热议问题