Sunday 15 June 2014

Check if at least one child has a specific value with xslt 1.0 -



Check if at least one child has a specific value with xslt 1.0 -

this xml:

<light_information_list> <light_information> <light_characteristics>al</light_characteristics> <light_colour>w-g</light_colour> </light_information> <light_information> <light_characteristics>al</light_characteristics> <light_colour>w-r</light_colour> </light_information> <light_information> <light_characteristics>f</light_characteristics> <light_colour>r</light_colour> </light_information> <light_information> <light_characteristics>f</light_characteristics> <light_colour>g</light_colour> </light_information> <light_information> <light_characteristics>f</light_characteristics> <light_colour>w</light_colour> </light_information> </light_information_list>

i woul insert control:

if @ to the lowest degree 1 element of light_colour light_information_list contain '-'

i tried whit this, wrong:

<xsl:choose> <xsl:when test="not(contains(.,'-'))"> <!-- --> </xsl:when> <xsl:otherwise> <!-- b --> </xsl:otherwise> </xsl:choose>

this xslt code:

<xsl:for-each select="light_information"> <xsl:for-each select="light_colour"> <xsl:choose> <xsl:when test="not(contains(.,'-'))"> <!-- test required --> <xsl:choose> <xsl:when test="following-sibling::light_range >= 15"> <span style="font-family:univers condensed; font-weight:bold;"> <xsl:if test="not(preceding::light_colour[1][preceding::immutable_id = $ef])"> <xsl:value-of select="."/> </xsl:if> <xsl:if test=". != preceding::light_colour[1][preceding::immutable_id = $ef]"> <xsl:value-of select="."/> </xsl:if> </span> </xsl:when> <xsl:otherwise> <xsl:if test="not(preceding::light_colour[1][preceding::immutable_id = $ef])"> <xsl:value-of select="."/> </xsl:if> <xsl:if test=". != preceding::light_colour[1][preceding::immutable_id = $ef]"> <xsl:value-of select="."/> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> ciao <!-- insert command here if light_colour contain '-' --> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:for-each>

now output is:

ciao ciao r g w

i would, if 1 element in node of light_information_list contains light_colour '-' write 'ciao'

thi solution:

<xsl:for-each select="light_information"> <xsl:choose> <xsl:when test="not(contains(parent::light_information_list//light_colour, '-'))"> <!-- solution --> <xsl:for-each select="light_colour"> <xsl:choose> <xsl:when test="following-sibling::light_range >= 15"> <span style="font-family:univers condensed; font-weight:bold;"> <xsl:if test="not(preceding::light_colour[1][preceding::immutable_id = $ef])"> <xsl:value-of select="."/> </xsl:if> <xsl:if test=". != preceding::light_colour[1][preceding::immutable_id = $ef]"> <xsl:value-of select="."/> </xsl:if> </span> </xsl:when> <xsl:otherwise> <xsl:if test="not(preceding::light_colour[1][preceding::immutable_id = $ef])"> <xsl:value-of select="."/> </xsl:if> <xsl:if test=". != preceding::light_colour[1][preceding::immutable_id = $ef]"> <xsl:value-of select="."/> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:when> <xsl:otherwise> ciao </xsl:otherwise> </xsl:choose> </xsl:for-each>

insert command @ head , using parent.

xslt xslt-1.0

No comments:

Post a Comment