XSLT映射以删除双引号,其中包含PIPE分隔符



专家们,我需要编写XSLT 1.0代码来消除双引号内的Pipe分隔符,还需要删除那些双引号..

输入:

<?xml version="1.0" encoding="utf-8"?>
<ns:MT_FILE>
<LN>
<LD>EXTRACT|"28|53"|1308026.7500|1176</LD>
</LN>
<LN>
<LD>DETAIL|1176|"LOS LE|OS PARRILLA"|Y|R||||<LD>
</LN>

</ns:MT_FILE>

**期望输出:**

<?xml version="1.0" encoding="utf-8"?>
<ns:MT_FILE>
<LN>
<LD>EXTRACT|2853|1308026.7500|1176</LD>
</LN>
<LN>
<LD>DETAIL|1176|LOS LE OS PARRILLA|Y|R||||<LD>
</LN>

</ns:MT_FILE>

**使用的XSLT如下:**

<?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>

这个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="text()">
<xsl:call-template name="process">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="process">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '&quot;')">
<xsl:value-of select="substring-before($text, '&quot;')"/>
<xsl:value-of select="translate(substring-before(substring-after($text, '&quot;'), '&quot;'), '|', '')"/>
<xsl:call-template name="process">
<xsl:with-param name="text" select="substring-after(substring-after($text, '&quot;'), '&quot;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

标记为EXSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:regexp="http://exslt.org/regular-expressions"
exclude-result-prefixes="regexp">

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="LD/text()">
<xsl:value-of select="regexp:replace(., '(&quot;)([^|]+)|([^&quot;]+)(&quot;)', 'g', '$2$3')"/>
</xsl:template>

</xsl:stylesheet>