This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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()&gt;1]"/>
    </residents>
</xsl:template>

<xsl:template match="RESPONSES/RESPONSE[position()&gt;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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]