Tina Dsouza
Tina Dsouza

Reputation: 1

Unable to split and merge in XSLT

I have an Xml

<input Inputxml="&ltOrder..&lt;LinePPlineNO=&quot;1@quot;Line/&gt; &gt;" >

How do i remove some part of string using xsl .. for eg I need to remove a whole string from &lt; to &gt; for a PPline 1

I need to splie the string in 3 parts remove the string from lt to gt and merge the part 1na dpart 3 of string

  <Test Attrib1="b" Attrib2="C" Inputxml="
      &lt;OrderLine  OrderedQty="1" PrimeLineNo="1" ShipNode="ABC" $gt;
       &lt;/OrderLine $gt;
     &lt;OrderLine OrderedQty="1" PrimeLineNo="2" ShipNode="ABC"  $gt;      
  &lt;/OrderLine $gt;" />

For example I may have 100 Order lines but I need to find the one with Prime line 1 and remove it .. So if I have to remeove a line I have to remove from lt; to gt;

Upvotes: 0

Views: 78

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117140

Your example is confusing. If you have an XML input such as:

<input Inputxml="&lt;order&gt;&lt;Line PPlineNO=&quot;1&quot;&gt;Bingo&lt;/Line&gt;&lt;/order&gt;"/>

where the Inputxml attribute holds the escaped XML:

<order><Line PPlineNO="1">Bingo</Line></order> 

you can use:

<xsl:template match="input">
    <result>
        <xsl:value-of select="substring-before(substring-after(@Inputxml, 'PPlineNO=&quot;1&quot;&gt;'), '&lt;/Line&gt;')" />
    </result>
</xsl:template>

to get:

<result>Bingo</result>

Note that is not a good way to parse XML (or rather what used to be XML). It would be much smarter to unescape it first, then parse it as XML. In XSLT 3.0, you can use the parse-xml() function for this. In XSLT 1.0/2.0, you can do:

<xsl:value-of select="@Inputxml" disable-output-escaping="yes"/>

save the result to a file, and process the resulting file using another XSLT stylesheet.

Upvotes: 1

Related Questions