Jump to content
Print XML Table with XSL
Asked by Philip F
Posted Sep 26 2012 12:00 PM
I apologize in advance if this is too simple, but I am not a programmer.
I am trying to display an XML file with XSL, the XML file is a list of groups and their subsequent users (the info displayed below is not everything, as there are 20+ addtl groups). The problem is that various groups have varying number of users. I can write a simple xsl statement to display the first user per group, but I don't know how to include all users.
The XML is:
<?xml-stylesheet type="text/xsl" href="groups.xsl" ?>
The XSL is:
<table width="100%" border="1">
<TD colspan="2" align="center">Users</TD>
<TD width="50%"><xsl:value-of select="cn" /></TD>
<TD width="50%"><xsl:value-of select="UserList/uid" /></TD>
Thanks in advance
Answered by mhalverson
Posted Sep 26 2012 03:23 PM
You can nest a second for-each loop to process all of the uid's. You will have to decide how you want to list them (for example separate TD's).
For example if you want to stay with your two column table and separate them by commas replace <xsl:value-of select="UserList/uid" /> with :
<xsl:if test="not(position()=last())">,<xsl:text> </xsl:text></xsl:if>
This will loop over all the uid's (the sort puts them in alphabetical order leave that out if you want document order). The test element will add a comma and a space after each unless it is the last one (in the alphabetical order if the sort is present else document order). The text element ensures that the space does not get clobbered by whatever whitespace handling is present (there are other ways to do that). The periods in the select statements refer to the current context node (in this case the uid).
Answered by Philip F
Posted Sep 27 2012 12:24 PM
Thanks a lot for your help!