[DDI-users] XSLT: How to iterate over contained var's or varGrp's

Joachim Wackerow wackerow at zuma-mannheim.de
Fri Oct 15 10:15:35 EDT 2004


Andrew

With a small time lag I read by chance your question.

If an attribute is defined as IDREFS in the DTD like the attribute var 
of the element varGrp and you are using the DDI DTD in the DDI document, 
you could use the XPath function id() (see 
http://www.w3c.org/TR/xpath#section-Node-Set-Functions).

It will give you a node-set, over which you could iterate, like:

<xsl:for-each select="id(/codeBook/dataDscr/varGrp/@var)">
   <xsl:value-of select="labl"/>
</xsl:for-each>

Achim

Andrew L Arnott wrote:

> Quick question on XSLT:
> 
> If I have a varGrp with 5 var's referenced in it,
> <varGrp ID="VG1" var="V1 V2 V3 V4 V5"/>
> 
> And of course the necessary variables also in the XML, then how do I iterate
> over those variables in XSLT?  I have used EXSLT to tokenize the string and
> then do a search like this:
> <xsl:variable name="IDlist"
> select="ExsltStrings:tokenize(/codeBook/dataDscr/varGrp[@ID='VG1']"/>
> <xsl:variable name="varList" select="/codeBook/dataDscr/var[@ID=$IDlist]"/>
> <xsl:for-each select="varList">
> 	...
> </xsl:for-each>
> 
> But I want to get away from using extension methods.  It seems like
> something this common would be provided for in XSLT, maybe using xsl:key or
> something like that.  But I just don't know it. Can someone please advise?
> 
> Thanks,
> Andrew
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> DDI-users mailing list
> DDI-users at icpsr.umich.edu
> http://www.icpsr.umich.edu/mailman/listinfo/ddi-users



More information about the DDI-users mailing list