[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] xsl transormation from flat tree to hierarchical tree


Subject: Re: [xsl] xsl transormation from flat tree to hierarchical tree
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Sat, 24 Mar 2012 19:15:43 +0000

Hi Andreas,
   My apologies for a delayed response (since this question was directed to
me).

I think, I don't have a concrete suggestion for your new question
below, since it seems to me that this question is very specific to
your application domain.

I'll leave it to anyone else to answer this, or I wish you good luck
to discover the answer yourself.

On Sun, Mar 18, 2012 at 10:30 AM, Andreas Volz <lists@xxxxxxxxxxxxx> wrote:
> Am Sat, 10 Mar 2012 16:00:47 +0530 schrieb Mukul Gandhi:
>
> Hi Mukul,
>
> thanks for that hints! I never used that call-templates before. After
> some experiments I got it somehow running in my xsl:
>
> o;?<?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template name="printStateTree"
xmlns:dotml="http://www.martin-loetzsch.de/DOTML">
> B  B  <xsl:param name="curState"/>
>
> B  B  B <xsl:element name="node">
>
> B  B  B  B  B <xsl:attribute name="id"><xsl:value-of
select="$curState/@name"/>
> B  B  B  B  B </xsl:attribute>
>
> B  B  B  B  B <xsl:attribute name="label"><xsl:value-of
select="$curState/@name"/>
> B  B  B  B  B </xsl:attribute>
>
> B  B  B  B  B <xsl:attribute name="fontname">Arial</xsl:attribute>
>
> B  B  B  B  B <xsl:attribute name="fontsize">9</xsl:attribute>
>
> B  B  B  B  B <xsl:for-each select="//state[@parent = $curState/@name]">
>
> B  B  B  B  B  B  B <xsl:call-template name="printStateTree">
> B  B  B  B  B  B  B  B  B <xsl:with-param name="curState" select="."/>
> B  B  B  B  B  B  B </xsl:call-template>
>
> B  B  B  B  </xsl:for-each>
>
> B  B  B </xsl:element>
>
> </xsl:template>
>
> <xsl:template match="/">
> B  B <dotml:graph file-name="stateval"
xmlns:dotml="http://www.martin-loetzsch.de/DOTML"
> B  B  B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> B  B  B xsi:schemaLocation="http://www.martin-loetzsch.de/DotML
../dotml-1.3/dotml-1.3.xsd" label="stateval" fontcolor="#0000A0"
fontname="Arial Bold" margin="0.2,0.1" ranksep="0.2" nodesep="0.5"
> B  B  B bgcolor="#F0F0FF" fontsize="13" style="dashed">
>
> B  B  B  B <xsl:for-each select="stateval/states">
>
> B  B  B  B  B <xsl:call-template name="printStateTree">
> B  B  B  B  B  B  B  <xsl:with-param name="curState"
select="state[not(@parent)]"/>
> B  B  B  B  B </xsl:call-template>
>
> B  B  B  B </xsl:for-each>
>
> B  B  B  B <xsl:for-each select="stateval/transitions/transition">
> B  B  B  B  B  B <dotml:edge>
> B  B  B  B  B  B  B  B <xsl:attribute name="from"><xsl:value-of
select="@from"/>
> B  B  B  B  B  B  B  B </xsl:attribute>
>
> B  B  B  B  B  B  B  B <xsl:attribute name="to"><xsl:value-of
select="@to"/>
> B  B  B  B  B  B  B  B </xsl:attribute>
>
> B  B  B  B  B  B  B  B <xsl:attribute name="label"><xsl:value-of
select="@event"/>
> B  B  B  B  B  B  B  B </xsl:attribute>
>
> B  B  B  B  B  B  B  B <xsl:attribute name="fontname">Arial</xsl:attribute>
>
> B  B  B  B  B  B  B  B <xsl:attribute name="fontsize">7</xsl:attribute>
> B  B  B  B  B  B </dotml:edge>
> B  B  B  B </xsl:for-each>
>
> B  B </dotml:graph>
> </xsl:template>
>
> <xsl:template match="*|text()|@*">
> B  B <xsl:copy>
> B  B  B  B <xsl:apply-templates select="@*"/>
> B  B  B  B <xsl:apply-templates/>
> B  B </xsl:copy>
> </xsl:template>
>
>
> </xsl:stylesheet>
>
> But the output is still not as I need it:
>
> <?xml version="1.0"?>
> <dotml:graph xmlns:dotml="http://www.martin-loetzsch.de/DOTML"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" file-name="stateval"
xsi:schemaLocation="http://www.martin-loetzsch.de/DotML
../dotml-1.3/dotml-1.3.xsd" label="stateval" fontcolor="#0000A0"
fontname="Arial Bold" margin="0.2,0.1" ranksep="0.2" nodesep="0.5"
bgcolor="#F0F0FF" fontsize="13" style="dashed">
> B  B <node id="Root" label="Root" fontname="Arial" fontsize="9">
> B  B  B  B <node id="Initial" label="Initial" fontname="Arial" fontsize="9"
/>
> B  B  B  B <node id="Final" label="Final" fontname="Arial" fontsize="9" />
> B  B  B  B <node id="Main" label="Main" fontname="Arial" fontsize="9" />
> B  B  B  B <node id="Browser" label="Browser" fontname="Arial" fontsize="9"
/>
> B  B  B  B <node id="Settings" label="Settings" fontname="Arial"
fontsize="9" />
> B  B  B  B <node id="EMail_Compound" label="EMail_Compound" fontname="Arial"
fontsize="9">
> B  B  B  B  B  B <node id="EMail_Compound_Initial"
label="EMail_Compound_Initial" fontname="Arial" fontsize="9" />
> B  B  B  B  B  B <node id="EMail_Compound_History"
label="EMail_Compound_History" fontname="Arial" fontsize="9" />
> B  B  B  B  B  B <node id="EMail_Read" label="EMail_Read" fontname="Arial"
fontsize="9" />
> B  B  B  B  B  B <node id="EMail_Compose" label="EMail_Compose"
fontname="Arial" fontsize="9" />
> B  B  B  B </node>
> B  B </node>
> B  B <dotml:edge from="Initial" to="Main" label="" fontname="Arial"
fontsize="7" />
> B  B <dotml:edge from="Root" to="Final" label="EXIT" fontname="Arial"
fontsize="7" />
> B  B <dotml:edge from="Root" to="Main" label="MAIN" fontname="Arial"
fontsize="7" />
> B  B <dotml:edge from="Root" to="Browser" label="BROWSER" fontname="Arial"
fontsize="7" />
> B  B <dotml:edge from="Root" to="Settings" label="SETTINGS" fontname="Arial"
fontsize="7" />
> B  B <dotml:edge from="Root" to="EMail_Compound" label="EMAIL"
fontname="Arial" fontsize="7" />
> B  B <dotml:edge from="EMail_Compound" to="EMail_Compound_Initial" label=""
fontname="Arial" fontsize="7" />
> B  B <dotml:edge from="EMail_Compound_Initial" to="EMail_Compound_History"
label="" fontname="Arial" fontsize="7" />
> B  B <dotml:edge from="EMail_Compound_History" to="EMail_Read" label=""
fontname="Arial" fontsize="7" />
> B  B <dotml:edge from="EMail_Compound" to="EMail_Compose"
label="EMAIL_COMPOSE" fontname="Arial" fontsize="7" />
> B  B <dotml:edge from="EMail_Compound" to="EMail_Read" label="EMAIL_READ"
fontname="Arial" fontsize="7" />
> </dotml:graph>
>
> It has now correct transformation into a parent relation, but dotml needs
format like this:
>
> <record >
> B <node B  B  B  B  id="10" label="left"/>
> B <node B  B  B  B  id="11" label="middle"/>
> B <node B  B  B  B  id="12" label="right"/>
> </record>
>
> <record >
> B <node B  B  B  B  id="20" label="one"/>
> B <node B  B  B  B  id="21" label="two"/>
> </record>
>
> I tried to learn more about xsl by reading w3schools docu, but I wasn't able
to
> get exact that result. So I like to have this:
>
> Could you maybe give me please another hint?
>
> regards
> B Andreas




--
Regards,
Mukul Gandhi


Current Thread
Keywords
xsl