Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Question regarding XSL

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 9/16/2009 7:53:00 PM
Rudolf wrote:
> height is an attribute in the xml
> 
> i am using XSLT2.0


Here is an example, assuming an XML input alike

<data>
   <item height="10"/>
   <item height="20"/>
   <item height="30"/>
</data>

then this stylesheet below

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="2.0"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:mf="http://example.com/2009/mf"
   xmlns="http://www.w3.org/2000/svg"
   exclude-result-prefixes="xs mf">

   <xsl:output indent="yes"/>

   <xsl:template match="/">
     <svg>
       <xsl:call-template name="mf:make-rects">
         <xsl:with-param name="items" select="data/item"/>
         <xsl:with-param name="xcoord" select="10"/>
         <xsl:with-param name="ycoord" select="10"/>
       </xsl:call-template>
     </svg>
   </xsl:template>

   <xsl:template name="mf:make-rects">
     <xsl:param name="items" as="element()*"/>
     <xsl:param name="xcoord" as="xs:integer"/>
     <xsl:param name="ycoord" as="xs:integer"/>
     <xsl:if test="$items[1]">
       <rect x="{$xcoord}" y="{$ycoord}" width="10" 
height="{$items[1]/@height}" fill="green"/>
       <xsl:call-template name="mf:make-rects">
         <xsl:with-param name="items" select="$items[position() gt 1]"/>
         <xsl:with-param name="xcoord" select="$xcoord"/>
         <xsl:with-param name="ycoord" select="$ycoord + 1 + 
xs:integer($items[1]/@height)"/>
       </xsl:call-template>
     </xsl:if>
   </xsl:template>

</xsl:stylesheet>

creates the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg">
    <rect x="10" y="10" width="10" height="10" fill="green"/>
    <rect x="10" y="21" width="10" height="20" fill="green"/>
    <rect x="10" y="42" width="10" height="30" fill="green"/>
</svg>

-- 

	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