XSLT Expand input XML using a for-loop type operation

Ievnxsrr

New Member
I'm new to XSLT, forgive my ignorance, if I have input XML like this:\[code\]<Doc> <stuff> <for var="i" from="1" to="2"> <item>$(i)></item> <for var="j" from="2" to="4"> <innerItem>$(j)</innerItem> </for> </for> </stuff></Doc>\[/code\]I want to use a transform to have the output XML expanded like this:\[code\]<Doc> <stuff> <item>1</item> <innerItem>2</innerItem> <innerItem>3</innerItem> <innerItem>4</innerItem> <item>2</item> <innerItem>2</innerItem> <innerItem>3</innerItem> <innerItem>4</innerItem> </stuff></Doc>\[/code\]All I've got is this: what to do next?\[code\]<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="for"> <xsl:variable name="from" select="@from" /> <xsl:variable name="to" select="@to" /> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template></xsl:stylesheet>\[/code\]
 
Back
Top