简体   繁体   English

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

[英]XSLT mapping to remove double quotes which has PIPE delimited symbol inside

Experts, i need to write XSLT 1.0 code to eliminate the Pipe delimited symbol inside double quotes and also need to remove those double quotes..专家,我需要编写 XSLT 1.0 代码来消除双引号内的 Pipe 分隔符号,还需要删除那些双引号..

Input:输入:

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

** Desired Output:** ** 所需 Output:**

<?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 I used is below:** ** 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>

This XSLT removing all the double quotes from my input field, please assist here..这个 XSLT 从我的输入字段中删除所有双引号,请在这里协助..

If it can be assumed that quotes will always come in pairs, you could do:如果可以假设引号总是成对出现,你可以这样做:

XSLT 1.0 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>

As you tagged as EXSLT:当您标记为 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM