Subject: Re: [xsl] processing multiple values in a single attribute From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 15 May 2009 18:39:36 -0400 |
I would add that you should use <xsl:choose> and have two <xsl:when> tests:
<xsl:choose> <xsl:when test="not($string = '') and contains($string,' ')"> <statemanipulation> <variableref name="{substring-before($string,' ')}"/> <fault fault-code="{substring-before($string,' ')}" fault-state="ok"/> </statemanipulation> <xsl:call-template name="do-tokens"> <xsl:with-param name="string" select="substring-after($string,' ')"/> </xsl:call-template> </xsl:when> <xsl:when test="not($string = '')"> <statemanipulation> <variableref name="{$string}"/> <fault fault-code="{$string}" fault-state="ok"/> </statemanipulation> </xsl:when> </xsl:choose> in order to ensure it grabs the last value of the string.
T:\ftemp>type o.xml <FAULT-REF FAULTS="PF01 PF02 PF03 PF04 PF05 PF06 PF07 PF08 PF09 PF10 PF11"/>
T:\ftemp>type o.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="FAULT-REF"> <xsl:call-template name="do-tokens"> <xsl:with-param name="string" select="concat(normalize-space(@FAULTS),' ')"/> </xsl:call-template> </xsl:template>
<xsl:template name="do-tokens"> <xsl:param name="string"/> <xsl:if test="contains($string,' ')"> <statemanipulation> <variableref name="{substring-before($string,' ')}"/> <fault fault-code="{substring-before($string,' ')}" fault-state="ok"/> </statemanipulation> <xsl:call-template name="do-tokens"> <xsl:with-param name="string" select="substring-after($string,' ')"/> </xsl:call-template> </xsl:if> </xsl:template>
</xsl:stylesheet> T:\ftemp>call xslt o.xml o.xsl <?xml version="1.0" encoding="utf-8"?> <statemanipulation> <variableref name="PF01"/> <fault fault-code="PF01" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF02"/> <fault fault-code="PF02" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF03"/> <fault fault-code="PF03" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF04"/> <fault fault-code="PF04" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF05"/> <fault fault-code="PF05" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF06"/> <fault fault-code="PF06" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF07"/> <fault fault-code="PF07" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF08"/> <fault fault-code="PF08" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF09"/> <fault fault-code="PF09" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF10"/> <fault fault-code="PF10" fault-state="ok"/> </statemanipulation> <statemanipulation> <variableref name="PF11"/> <fault fault-code="PF11" fault-state="ok"/> </statemanipulation> T:\ftemp>
-- XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08 Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] processing multiple value, vasu chakkera | Thread | Re: [xsl] processing multiple value, Matthew L. Avizinis |
Re: [xsl] processing multiple value, vasu chakkera | Date | Re: [xsl] processing multiple value, Matthew L. Avizinis |
Month |