Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Question regarding XSL [Thread Next] Re: Question regarding XSLTo: 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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
