Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Possible to keep a variable value after for-each

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 5/1/2009 12:57:00 PM
Gina_Marano wrote:

> ok, I will try to make an example:
> 
> 
> <parts>
>   <component>
>     <description>Item123_cover</description>
>     <color>white</color>
>     <weight>80</weight>
>   <component>
>   <component>
>     <description>Item123_block</description>
>     <weight>100</weight>
>     <pagecount>156</pagecount>
>   <component>
> </parts>
> 
> -note, the above can be in any order
> 
> generating:
> 
> <order>
>   <cover>
>     <color>white</color>
>     <case>(if Item123_block.weight = 100 then 'A' if
> Item123_block.weight = 80 then 'B')</case>
>   </cover>
>   <block>
>     <pagecount>156</pagecount>
>     <weight>100</weight>
>     <size>8x11</size>
>   </block>
> <block>
> 
> NOTE: the <cover><case> is dependant on the Item123_block's  weight.

I am not sure whether the contents of the case element is meant to be 
literal content you want to generate or some attempt to use a pseudo 
code language to show what you want.

In case that is meant literal then here is a stylesheet:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="parts">
     <order>
       <xsl:variable name="b" select="component[contains(description, 
'block')]"/>
       <xsl:variable name="c" select="component[contains(description, 
'cover')]"/>
       <xsl:variable name="A" select="&quot;'A'&quot;"/>
       <xsl:variable name="B" select="&quot;'B'&quot;"/>
       <cover>
         <xsl:copy-of select="$c/color"/>
         <case>
           <xsl:value-of select="concat('(if ', $b/description,
'.weight = ', $b/weight, ' then ', $A, ' if ', $b/description,
'.weight = ', $c/weight, ' then ', $B, ')')"/>
         </case>
       </cover>
       <block>
         <xsl:copy-of select="$b/pagecount"/>
         <xsl:copy-of select="$b/weight"/>
         <size>8x11</size>
       </block>
     </order>
   </xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent