|
Subject: Re: [xsl] processing multiple values in a single attribute From: "Matthew L. Avizinis" <mla@xxxxxxxxx> Date: Fri, 15 May 2009 19:36:03 -0400 |
Hello again,
Despite my slight embarrassment earlier, dare I ask a further question
for my own curiosity please?
Suppose (I'm not saying OPs data could ever fit this condition) instead of
<FAULT-REF FAULTS="PF01 PF02 PF03 PF04 PF05 PF06 PF07 PF08 PF09 PF10
PF11"/>
you had
<FAULT-REF FAULTS=" "/> or <FAULT-REF FAULTS=""/>.
Would you change the templates at all? If so, how?
Peace,
Matthew Avizinis
G. Ken Holman wrote:
> At 2009-05-15 18:29 -0400, Matthew L. Avizinis wrote:
>> 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.
>
> I am unsure why you are bringing this up and introducing unnecessary
> complexity.
>
> I avoided all that complexity you suggest by passing an initial string
> with expected values. My transcript proved that the last value of the
> string was being grabbed. I've repeated the transcript below.
>
> What benefits are obtained by replacing my single test of a single
> condition with your two tests of three conditions?
>
> Also, you have two creations of the result tree that now need to be
> maintained in unison ... an easy human error would be to update one
> and not the other.
>
> Furthermore:
>
> <xsl:when test="not($string = '') and contains($string,' ')">
>
> is equivalent to:
>
> <xsl:when test="contains($string,' ')">
>
> ... because if it contains a space then it must not be empty.
>
> I hope this helps clarify the archive regarding your statements that
> the suggested solution "should" be changed. I don't see that it does
> at all.
>
> . . . . . . . . . . . . . Ken
>
> 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:output indent="yes"/>
>
> <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, Matthew L. Avizinis | Thread | Re: [xsl] processing multiple value, David Carlisle |
| RE: [xsl] sorting on decimal, Don Smith | Date | [xsl] Please look at my mini-templa, Dmitri Snytkine |
| Month |