On Feb 21, 3:52 pm, peter_han...@yahoo.com wrote:
> <Info>
> <CtrlUnit>unit1</CtrlUnit>
> <Freq>1</Freq>
> <Freq>2</Freq>
> <CtrlUnit>unit2</CtrlUnit>
> <Freq>100</Freq>
> </Info>
>
> And I want to translate it to this:
>
> <Info>
> <CtrlUnit>unit1<x:br/>1<x:br/>2</CtrlUnit>
> <CtrlUnit>unit2<x:br/>100</CtrlUnit>
> </Info>
>
> So to select following Freqs but only to next CtrUnit.
First of all, apply your evil-removal tool (I favour
shovels) to whoever designed that XML.
<Info>
<CtrlUnit name="unit1">
<Freq>1</Freq>
<Freq>2</Freq>
</CtrlUnit>
<CtrlUnit name="unit2">
<Freq>100</Freq>
</CtrlUnit>
</Info>
Is way more logical, and you wouldn't have to face your
present problems if it was designed that way from the
start.
> How can I achieve this?
However, since it is possible that you have no power over
your source XML's structure, and since grouping problems
are sometimes unavoidable anyway, here's a way to do this:
<xsl:stylesheet version="1.0"
xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="ctrl-unit" match="Freq"
use="generate-id(preceding-sibling::CtrlUnit[1])"/>
<xsl:template match="Info">
<xsl:copy>
<xsl:apply-templates select="CtrlUnit"/>
</xsl:copy>
</xsl:template>
<xsl:template match="CtrlUnit">
<xsl:copy>
<xsl:apply-templates/>
<xsl:apply-templates
select="key('ctrl-unit',generate-id(.))"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Freq">
<br/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Google XSL FAQ, it has a lot of highly useful info on
grouping, as well as about a zillion other problems.
--
Pavel Lepin