Subject: AW: [xsl] How to XSLT concat string, remove last comma From: "Dr. Patrik Stellmann patrik.stellmann@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 7 Oct 2016 07:34:25 -0000 |
The position() and last() take the list of all CUSTOMER elements as reference b not just those with bAmount = 0b. To fix your solution just put the condition in the select: <xsl:for-each select="CUSTOMERS/CUSTOMER[Amount = 0]"> <xsl:value-of select="ID"/> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:for-each> With XPath 2.0 you could simplify this to a single xpath expression using string-join: <xsl:value-of select="string-join(CUSTOMERS/CUSTOMER[Amount = 0]/ID, ',')"/> Patrik ------------------------------------------------------------------ Systemarchitektur & IT-Projekte Tel: +49 40 33449-1142 Fax: +49 40 33449-1400 E-Mail: Patrik.Stellmann@xxxxxxxxx<mailto:Patrik.Stellmann@xxxxxxxxx> [https://www.gdv-dl.de/fileadmin/user_upload/bild/Bilder_auf_Website/Zentralr uf/160921_Entwurf_DKM-Banner_Signatur_65_small.jpg]<http://www.die-leitmesse. de/zentralruf-autoversicherer/2016> Von: Rahul Singh rahulsinghindia15@xxxxxxxxx [mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx] Gesendet: Freitag, 7. Oktober 2016 09:23 An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Betreff: [xsl] How to XSLT concat string, remove last comma Hi, I need to build up a string using XSLT and separate each string with a comma but not include a comma after the last string. Here i have mentioned our XSL but i am geetting comma in my output. Input: <?xml version="1.0"?> <CUSTOMERS> <CUSTOMER> <ID>441</ID> <Item_no>24</Item_no> <Amount>0</Amount> </CUSTOMER> <CUSTOMER> <ID>900817</ID> <Item_no>28</Item_no> <Amount>0</Amount> </CUSTOMER> <CUSTOMER> <ID>00081</ID> <Item_no>4</Item_no> <Amount>1</Amount> </CUSTOMER> </CUSTOMERS> XSL: <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:template match="/"> <CUSTOMERS> <CUSTOMER> <Id> <xsl:for-each select="CUSTOMERS/CUSTOMER"> <xsl:if test="Amount = 0"> <xsl:value-of select="ID"/> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:if> </xsl:for-each> </Id> </CUSTOMER> </CUSTOMERS> </xsl:template> </xsl:stylesheet> My Output: <?xml version="1.0" encoding="UTF-8"?> <CUSTOMERS> <CUSTOMER> <Id>441,900817,</Id> </CUSTOMER> </CUSTOMERS> Expected output: <?xml version="1.0" encoding="UTF-8"?> <CUSTOMERS> <CUSTOMER> <Id>441,900817</Id> </CUSTOMER> </CUSTOMERS> XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list> EasyUnsubscribe<-list/2718916> (by email<>) GDV Dienstleistungs-GmbH & Co. KG GlockengieCerwall 1 D-20095 Hamburg www.gdv-dl.de Sitz und Registergericht: Hamburg HRA 93 894 USt.-IdNr : DE 205183123 KomplementC$rin: GDV Beteiligungsgesellschaft mbH Sitz und Registergericht: Hamburg HRB 71 153 GeschC$ftsfC<hrer: Dr. Jens Bartenwerfer Michael Bathke ------------------------------------------------------------------ Diese E-Mail und alle AnhC$nge enthalten vertrauliche und/oder rechtlich geschC<tzte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtC<mlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet. This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to XSLT concat string, re, Rahul Singh rahulsin | Thread | [xsl] using keys on variables, Graydon graydon@xxxx |
Re: [xsl] is the processing model o, Michael Kay mike@xxx | Date | Re: [xsl] is the processing model o, Mukul Gandhi gandhi. |
Month |