问题
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:
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(., '\"', '')"/>
</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>
来源:https://stackoverflow.com/questions/26750513/removing-double-quotes-in-xsl