I am trying to create a list of resources (tab delimited text, for output) from XML data. The trick, I need to take the string I created and list it several times (iteration ???) based on the number found in XML. So from the XML below:
<?xml version="1.0" encoding="UTF-8"?> <library> <aisle label="AA"> <row>bb</row> <shelf>a</shelf> <books>4</books> </aisle> <aisle label="BB"> <row>cc</row> <shelf>d</shelf> <books>3</books> </aisle> </library>
I need to take the value found in the "books" and then copy the text string so many times. The result is as follows:
Aisle Row Shelf Titles AA bb a AA bb a AA bb a AA bb a BB cc d BB cc d BB cc d
In this way, the owner of the inventory can then write in the headings found on each shelf. I have the basic structure of my XSL, but I'm not sure how to do the βiterationβ part.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0"> <xsl:output omit-xml-declaration="yes"/> <xsl:variable name="tab" select="'	'"/> <xsl:variable name="newline" select="' '"/> <xsl:template match="/"> <xsl:text>Aisle</xsl:text> <xsl:value-of select="$tab"/> <xsl:text>Row</xsl:text> <xsl:value-of select="$tab"/> <xsl:text>Shelf</xsl:text> <xsl:value-of select="$tab"/> <xsl:text>Titles</xsl:text> <xsl:value-of select="$newline"/> <xsl:for-each select="library/aisle"> <xsl:value-of select="@label"/> <xsl:value-of select="$tab"/> <xsl:value-of select="row"/> <xsl:value-of select="$tab"/> <xsl:value-of select="shelf"/> <xsl:value-of select="$tab"/> <xsl:value-of select="$tab"/> <xsl:value-of select="$newline"/> </xsl:for-each> </xsl:template> </xsl:stylesheet>
Any help would be greatly appreciated. For starters, is βiterationβ the right term to use for this?
Thanks!
source share