Thanks to Syd and Peter for such quick and helpful replies. Peter's
stylesheet does the trick, thank you so much Peter!! And thanks to Syd
for reminding me that I really should learn myself some Emacs :-)
Dot
On 4/11/07, Peter Baker <[log in to unmask]> wrote:
> This is just off the top of my head, Dot, but it sounds like a job for
> recursion.
>
> <xsl:template name="output-elements">
> <xsl:param name="n" select="0"/>
> <xsl:if test="n < 300">
> <xsl:element name="element">
> <xsl:attribute name="n">
> <xsl:value-of select="$n + 1"/>
> </xsl:attribute>
> </xsl:element>
> <xsl:text>
> </xsl:text>
> <xsl:call-template name="output-elements">
> <xsl:with-param name="n" select="$n + 1"/>
> </xsl:call-template>
> </xsl:if>
> </xsl:template>
>
> Untested, but 300 recursions should be no problem for most processors.
> Keep your finger near the reset button when you try it.
>
> Peter
>
> Dot Porter wrote:
> > Hi Everyone,
> >
> > Sorry, this is an XSLT question, not a TEI question, but I am going
> > nuts and I know that there are people on the list who might be able to
> > help me.
> >
> > I'm trying to make a stylesheet that will output an XML file
> > consisting of a root element that is the parent of a list of multiple
> > elements - the same element over and over again, the number of
> > occurrences to be determined by me (either in the stylesheet itself or
> > in the file I'm processing). I also want to give each of these
> > multiple elements an attribute @n="x" where "x" is the position of the
> > element (the first one is n="1", second is n="2" and so on).
> >
> > The output would look like this (say that I ask for five):
> >
> > <root>
> > <element n="1"/>
> > <element n="2"/>
> > <element n="3"/>
> > <element n="4"/>
> > <element n="5"/>
> > </root>
> >
> >
> > I started by building a stylesheet that I process against an XML file
> > that consists only of a <root> tag:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > version="2.0">
> >
> > <xsl:template match="/">
> > <xsl:element name="root">
> > <xsl:call-template name="element"/>
> > </xsl:element>
> > </xsl:template>
> >
> > <xsl:template name="element">
> > <xsl:element name="element">
> > <xsl:attribute name="n">
> > <xsl:value-of select="count(-1)"/>
> > </xsl:attribute>
> > </xsl:element>
> > </xsl:template>
> >
> >
> > </xsl:stylesheet>
> >
> > The resulting output looks like this:
> >
> > <root><element n="1"/></root>
> >
> >
> > I'm *hoping* that there is something I can do up around the
> > <call-template> that will allow me to specify how many of those
> > <element>s I want. Eventually I'll want upwards of 300 - which is why
> > I'd like a stylesheet to do this for me, rather than having to do it
> > all by hand :-) Or maybe there is even another way?
> >
> > Thanks for any assistance, and again I'm sorry for bringing up a
> > non-TEI question on the list.
> >
> > Dot
> >
>
>
--
***************************************
Dot Porter, University of Kentucky
#####
Program Coordinator
Collaboratory for Research in Computing for Humanities
[log in to unmask] 859-257-9549
#####
Editorial Assistant, REVEAL Project
Center for Visualization and Virtual Environments
[log in to unmask]
***************************************
|