Hi,
I am trying to generate a style sheet that will generate text
output. The output must be formatted in a text table. I have been able
to generate the table for most elements, but there is a set of three
elements that must appear on the same row, and they must be sorted by
the refDate attribute. Because this is output as text, I must print the
table line by line, instead of column by column.
I have accomplished this by first figuring out what column has the
most entries (in the example below this would be maritalStatus). Then I
do a for-each on that column, and print out each entry by indexing the
three node-sets. The problem is, since I am doing only one for-each
loop I can't seem to sort multiple columns. Here is an example...
XML----
<person>
<maritalStatus refDate="1993-06-24">divorce</maritalStatus>
<maritalStatus refDate="1997-01-15">marriage</maritalStatus>
<maritalStatus refDate="1989-04-11">marriage</maritalStatus>
<dateOfBirth>1968-04-05</dateOfBirth>
<religion refDate="1968-04-05">Roman Catholic</religion>
<religion refDate="1996-12-02">Lutheran</religion>
</person>
Output----
Marital Status Date of Birth
Religion
marriage (1997-01-15) 1968-04-05 Lutheran
(1996-12-02)
divorce (1993-06-24)
Roman Catholic (1968-04-05)
marriage (1989-04-11)
So my style sheet right now looks something like this...
I first figure out what column has the most elements, in this case the
left column so I say...
<xsl:for-each select="$left">
<xsl:variable name="for-each-pos" select="position()" />
<xsl:call-template name="print-entry">
<xsl:with-param name="entry" select="$left[ $for-each-pos ]"/>
</xsl:call-template>
<xsl:call-template name="print-entry">
<xsl:with-param name="entry" select="$middle[ $for-each-pos ]"/>
</xsl:call-template>
<xsl:call-template name="print-entry">
<xsl:with-param name="entry" select="$right[ $for-each-pos ]"/>
</xsl:call-template>
<xsl:text> </xsl:text>
</xsl:for-each>
The parameters left, middle, and right are node-sets of all the
person/maritalStatus, person/dateOfBirth, and person/religion elements,
respectively.
I can't figure out how to sort the right column when I am doing a
for-each on the left column. Does anyone know how I could do that? Can
I fit a <xsl:sort> into my currect structure somehow, or would I need to
redo how I print the tables? It seems as though I would have to sort
the right column node-set before I enter the for-each loop, but I don't
know that is possible in XSLT, because <xsl:sort> doesn't actually sort
the set, it just traverses the set in a sorted order, right? Any help
is greatly appreciated.
Thanks
--Ryan
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list