This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Performance with grouping
- From: Maulik Modi <MModi at qcorps dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 19 Mar 2002 16:12:53 -0600
- Subject: [xsl] Performance with grouping
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
I have the following XML :
<RESPONSES>
<RESPONSE>
<C0><![CDATA[Res_ID]]></C0>
<C1><![CDATA[Res_Type]]></C1>
<C2><![CDATA[Error]]></C2>
</RESPONSE>
<RESPONSE>
<C0><![CDATA[15760412_105755]]></C0>
<C1><![CDATA[SF-IND]]></C1>
<C2><![CDATA[Unverifiable Service Address]]></C2>
</RESPONSE>
<RESPONSE>
<C0><![CDATA[15930044_106686]]></C0>
</RESPONSE>
<RESPONSE>
<C0><![CDATA[15600408_106431]]></C0>
<C1><![CDATA[SF-IND]]></C1>
</RESPONSE>
</RESPONSES>
The actual XML could have several children like C0, C1, C2.......Cn and also
several RESPONSE tags. I need to dynamically extract the tagname from always
the first <RESPONSE> node and then do further processing to group each
node-set into a <resident> tag like:
<residents>
<resident>
<Res_ID>15760412_105755</Res_ID>
<Res_Type>SF-IND</Res_Type>
<Error>Unverifiable Service Address</Error>
</resident>
<resident>
<Res_ID>15930044_106686</Res_ID>
<Res_Type>SF-IND</Res_Type>
</resident>
<resident>
<Res_ID>15600408_106431</Res_ID>
<Res_Type>SF-IND</Res_Type>
</resident>
</residents>
However, what I have working so far is this:
<residents>
<resident>
<Res_ID>15760412_105755</Res_ID>
<Res_ID>15930044_106686</Res_ID>
<Res_ID>15600408_106431</Res_ID>
</resident>
<resident>
<Res_Type>SF-IND</Res_Type>
<Res_Type>SF-IND</Res_Type>
</resident>
<resident>
<Error>Unverifiable Service Address</Error>
</resident>
</residents>
using the following XSL (snippet):
<xsl:template match="/">
<residents>
<xsl:apply-templates
select="RESPONSES/RESPONSE[1]"/>
</residents>
</xsl:template>
<xsl:template match="RESPONSE[1]">
<xsl:for-each select="*">
<resident>
<xsl:apply-templates
select="../following-sibling::RESPONSE/*[local-name()=local-name(current())]
">
<xsl:with-param name="tagname"
select="normalize-space(.)"/>
</xsl:apply-templates>
</resident>
</xsl:for-each>
</xsl:template>
<xsl:template match="*">
<xsl:param name="tagname"/>
<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.
Any help would be appreciated. Thanks,
Maulik Modi
mmodi@qcorps.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list