Removing double quotes in XSL

2019-08-02 01:42发布

I am using XSL 1.0, I have this kind of XML-

<ID>"7080"</ID>
<NAME>"Media"</NAME>
<ADDRESS>
    <STREET_1>"400 Street"</STREET_1>
</ADDRESS>

The values are coming with Double Quotes. I am trying to remove these double quotes in XSL 1.0 and show up my Result as:

 <ID>7080</ID>
    <NAME>Media</NAME>
    <ADDRESS>
        <STREET_1>400 Street</STREET_1>
    </ADDRESS>

Also, I have tried it to apply translate function to the root element of the XML but it isn't working. Any suggestion would help!

1条回答
做个烂人
2楼-- · 2019-08-02 02:23

You can use translate to replace the (escaped) double quote with an empty char.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

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

    <xsl:template match="*/text()">
        <xsl:value-of select="translate(., '\&quot;', '')"/>
    </xsl:template>

</xsl:stylesheet>

When used with the identity transform above and a shoutcase XML root element wrapper, this returns:

<XML>
    <ID>7080</ID>
    <NAME>Media</NAME>
    <ADDRESS>
        <STREET_1>400 Street</STREET_1>
    </ADDRESS>
</XML>
查看更多
登录 后发表回答