|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Performance with grouping
Hi,
as far as I can see, you loop through the first response elements
children and refer then to the other responses
children. Since the first response element does only have three
children, the loop will fetch the first child (<c0/>)
and then process all following response nodes child elements which
contain the same element as currently processed by your xsl:for-each
loop. This results in your output, you have posted.
The following approach will solve your problem:
<xsl:template match="/">
<residents>
<xsl:apply-templates
select="RESPONSES/RESPONSE[position()>1]"/>
</residents>
</xsl:template>
<xsl:template match="RESPONSES/RESPONSE[position()>1]">
<resident>
<xsl:for-each select="*">
<xsl:apply-templates select="."/>
</xsl:for-each>
</resident>
</xsl:template>
<xsl:template match="*">
<xsl:variable name="tagName">
<xsl:value-of
select="normalize-space(RESPONSES/RESPONSE[1]/*[name()=name(current(
))]"/>
</xsl:variable>
<xsl:element name="{$tagName}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
: I could loop around and get the grouping how I need it. However,
because the
: source XML can get pretty large at times, I am looking for a
solution that
: would make the most sense performance wise. I am using
Xalan-J-2_2.
An even better approach would be to setup a key for the first
response elements children
and then refer to the elements via the key() function instead of
using the same xpath expression on each node
in the source document. Thus instead of declaring a variable named
tagName you could use a globally defined
key
<xsl:key name="tagNames" match="RESPONSES/RESPONSE[1]/*"
use="name()"/>
But: I don't know if it will work, since I had some problems using
functions in the USE attribute, myself.
And then refer to the tagName in question using
<xsl:variable name="tagName"><xsl:value-of
select="key('tagNames', name())"/></xsl:variable>
...
Hope this works, hope this helps, nevertheless it is the correct
direction =)
Bye
Carsten
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








