c# - Create result tree fragment variable -
i using xsl stylesheet output xsl:fo document svg chart embedded.
i having trouble taking array input, , splitting several smaller arrays, stored in variables svg template can applied different arrays generate 3 different charts. input looks (please note custom ns):
<root xmlns="http://xml.mynamespace.com"> <data> <list> <item> <id>1</id> <title>foo</title> <score>10</score> </item> <item> <id>2</id> <title>bar</title> <score>6</score> </item> <item> <id>3</id> <title>baz</title> <score>16</score> </item> <item> <id>4</id> <title>fizz</title> <score>14</score> </item> <item> <id>5</id> <title>buzz</title> <score>7</score> </item> </list> </data> </root> these value can split 3 distinct groups. trying split array list 3 separate variables template can applied turn them svg chart. svg transform known work array above, think problem way trying create variables. have tried few different ways, have had success (if can call that) using xsl:copy-of (again, please aware of ns):
<xslt:stylesheet xmlns:m="http://xml.mynamespace.com" version="1.0"> <xsl:variable name="group1"> <xsl:element name="m:list"> <xsl:copy-of select="/m:root/m:data/m:list/m:item[id <= 3]"/> </xsl:element> </xsl:variable> </xslt:stylesheet> and later variable used so:
<xsl:apply-templates select="msxsl:node-set($group1)/m:list" /> the reason putting them in variables because template creates svg expects input in format of <list> 1 or more child item elements. svg transform template so:
<xsl:template match="m:list"> <xsl:variable name="canvasheight" select="28 * count(m:item)"/> <svg height="{$canvasheight}"> <xsl:for-each select="m:item"> <!-- draw bar here --> </xsl:for-each> </svg> </xsl:template> the output when try transform variable svg above indicates list element created correctly (because template matches , svg element output) item elements aren't copied because for-each doesn't seem have executed , outputted height 0.
am incorrectly creating variable group1? or there easier way doesn't require splitting initial list separate variables?
well /m:root/m:data/m:list/m:item[id <= 3] have wrong case (id versus id) , wrong namespace (none versus m:id) in predicate.
Comments
Post a Comment