Unable to split and merge in XSLT

こ雲淡風輕ζ 提交于 2020-03-05 04:37:30

问题


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;


回答1:


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.



来源:https://stackoverflow.com/questions/58777137/unable-to-split-and-merge-in-xslt

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