2017-09-07 3 views
0

Ich versuche, gesamte Eingabe XML in einer Zeichenfolge für die weitere Verarbeitung zu kopieren, und ich habe auch eine Anforderung, Text von einem bestimmten Knoten (Plancode) vor dem Kopieren in die Variable zu entfernen. Darf ich wissen, wie kann ich dies mit XsltEntfernen von Text von einem Knoten in Eingabe-XML

erreichen

INPUT XML:

<CallMember> 
    <PlanD> 
     <abcpr>you</abcpr> 
     <Desd>Protection</Desd> 
     <plancode>76789</plancode> 
     <plaDesc>goody</plaDesc> 
    </PlanD> 
    <fType>ONLINE</fType> 
</CallMember> 

XSLT Ich versuche:

<?xml version="1.0" encoding="iso-8859-1"?> 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" xmlns:func="http://exslt.org/functions" xmlns:dp="http://www.datapower.com/extensions" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:tglfn="http://test.com/tgl" xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="#all" extension-element-prefixes="dp regexp"> 

    <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/> 
    <xsl:template match="/"> 

      <xsl:variable name="InputRequest"> 
       <xsl:copy-of select="."/>     
      </xsl:variable> 

      <xsl:variable name="modifiedRequest"> 
       <xsl:copy-of select="."/> 
       <plancode></plancode> 
      </xsl:variable> 
</xsl:template> 

OUTput i in der modifiedRequest Variable erwartet am:

<CallMember> 
    <PlanD> 
     <abcpr>you</abcpr> 
     <Desd>Protection</Desd> 
     <plancode></plancode> <!-- this value needs to get emptied --> 
     <plaDesc>goody</plaDesc> 
    </PlanD> 
    <fType>ONLINE</fType> 
</CallMember> 

Antwort

1

eine -Identity-Vorlage in Kombination mit einer (fast) leeren Vorlage zum Filtern verwenden und apply-templates es:

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xalan="http://xml.apache.org/xslt" 
    xmlns:func="http://exslt.org/functions" 
    xmlns:dp="http://www.datapower.com/extensions" 
    xmlns:regexp="http://exslt.org/regular-expressions" 
    xmlns:tglfn="http://test.com/tgl" 
    xmlns:date="http://exslt.org/dates-and-times" 
    exclude-result-prefixes="#all" extension-element-prefixes="dp regexp">  
    <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/> 

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

    <xsl:template match="/"> 

     <xsl:variable name="InputRequest"> 
      <xsl:copy-of select="."/> 
     </xsl:variable> 

     <!-- copies subtree except matching empty template --> 
     <xsl:variable name="modifiedRequest"> 
      <xsl:copy> 
      <xsl:apply-templates select="node()|@*" /> 
      </xsl:copy> 
     </xsl:variable> 

    </xsl:template> 

    <!-- (nearly) empty template copies only element without content --> 
    <xsl:template match="plancode"> 
     <xsl:copy /> 
    </xsl:template> 
</xsl:stylesheet> 
+0

Vielen Dank, es funktionierte wie ein Charme !! – sarma

Verwandte Themen