xsl-list
[Top] [All Lists]

Re: [xsl] Need help with tokenize functionality in XSLT 1.0

2020-08-25 16:00:13
Thank you very much for your input.

Yes. input can contain details about single order or multiple orders and it
might or might not end with ";".

On Tue, 25 Aug 2020 at 16:53, David Carlisle 
d(_dot_)p(_dot_)carlisle(_at_)gmail(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

You changed the format. in the form you showed originally every item
terminated with a ; you had two items, and two ;
the form you show now has one item but no ;

You could add the trailing  ; by making the initial param

<xsl:param name="details" select="concat(invoiceDetails,';')"/>

On Tue, 25 Aug 2020 at 21:41, Prady Prady 
prady(_dot_)chin(_at_)gmail(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

This works good. Thanks for the solution.


But this is not working if there is only one order

eg:
=====================
Input xml:

<Payments>

<Payment>

<invoiceDetails>order1#amt1</invoiceDetails>

</Payment>

</Payments>

I need to be able to convert this to:
Output xml:

<Orders>

<Order>

<OrderNumber>order1</OrderNumber>

<Amount>amt1</Amount>

</Order>

</Orders>
======================

On Thu, 20 Aug 2020 at 12:52, Leo Studer 
leo(_dot_)studer(_at_)varioweb(_dot_)ch <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Nice, a recursive template with a parameter ;-)

Cheers
Leo



<xsl:template match="Payment">
 <xsl:param name="details" select="invoiceDetails"/>
 <xsl:variable name="car" select="substring-before($details,';')"/>
 <xsl:variable name="cdr" select="substring-after($details,';')"/>
 <Order>
  <OrderNumber><xsl:value-of
select="substring-before($car,'#')"/></OrderNumber>
  <Ammount><xsl:value-of select="substring-after($car,'#')"/></Ammount>
 </Order>
 <xsl:if test="contains($cdr,'#')">
  <xsl:apply-templates select=".">
   <xsl:with-param name="details" select="$cdr"/>
  </xsl:apply-templates>
 </xsl:if>
</xsl:template>


XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by
email)

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/3397216> (by
email <>)

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>