Removing double quotes in XSL

我与影子孤独终老i 提交于 2020-01-16 04:54:07

问题


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(., '\&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>


来源:https://stackoverflow.com/questions/26750513/removing-double-quotes-in-xsl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!