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">
<xsl:param name="curState"/>
<xsl:element name="node">
<xsl:attribute name="id"><xsl:value-of select="$curState/@name"/>
</xsl:attribute>
<xsl:attribute name="label"><xsl:value-of select="$curState/@name"/>
</xsl:attribute>
<xsl:attribute name="fontname">Arial</xsl:attribute>
<xsl:attribute name="fontsize">9</xsl:attribute>
<xsl:for-each select="//state[@parent = $curState/@name]">
<xsl:call-template name="printStateTree">
<xsl:with-param name="curState" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="/">
<dotml:graph file-name="stateval" xmlns:dotml="http://www.martin-loetzsch.de/DOTML"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<xsl:for-each select="stateval/states">
<xsl:call-template name="printStateTree">
<xsl:with-param name="curState" select="state[not(@parent)]"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="stateval/transitions/transition">
<dotml:edge>
<xsl:attribute name="from"><xsl:value-of select="@from"/>
</xsl:attribute>
<xsl:attribute name="to"><xsl:value-of select="@to"/>
</xsl:attribute>
<xsl:attribute name="label"><xsl:value-of select="@event"/>
</xsl:attribute>
<xsl:attribute name="fontname">Arial</xsl:attribute>
<xsl:attribute name="fontsize">7</xsl:attribute>
</dotml:edge>
</xsl:for-each>
</dotml:graph>
</xsl:template>
<xsl:template match="*|text()|@*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</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">
<node id="Root" label="Root" fontname="Arial" fontsize="9">
<node id="Initial" label="Initial" fontname="Arial" fontsize="9" />
<node id="Final" label="Final" fontname="Arial" fontsize="9" />
<node id="Main" label="Main" fontname="Arial" fontsize="9" />
<node id="Browser" label="Browser" fontname="Arial" fontsize="9" />
<node id="Settings" label="Settings" fontname="Arial" fontsize="9" />
<node id="EMail_Compound" label="EMail_Compound" fontname="Arial" fontsize="9">
<node id="EMail_Compound_Initial" label="EMail_Compound_Initial" fontname="Arial" fontsize="9" />
<node id="EMail_Compound_History" label="EMail_Compound_History" fontname="Arial" fontsize="9" />
<node id="EMail_Read" label="EMail_Read" fontname="Arial" fontsize="9" />
<node id="EMail_Compose" label="EMail_Compose" fontname="Arial" fontsize="9" />
</node>
</node>
<dotml:edge from="Initial" to="Main" label="" fontname="Arial" fontsize="7" />
<dotml:edge from="Root" to="Final" label="EXIT" fontname="Arial" fontsize="7" />
<dotml:edge from="Root" to="Main" label="MAIN" fontname="Arial" fontsize="7" />
<dotml:edge from="Root" to="Browser" label="BROWSER" fontname="Arial" fontsize="7" />
<dotml:edge from="Root" to="Settings" label="SETTINGS" fontname="Arial" fontsize="7" />
<dotml:edge from="Root" to="EMail_Compound" label="EMAIL" fontname="Arial" fontsize="7" />
<dotml:edge from="EMail_Compound" to="EMail_Compound_Initial" label="" fontname="Arial" fontsize="7" />
<dotml:edge from="EMail_Compound_Initial" to="EMail_Compound_History" label="" fontname="Arial" fontsize="7" />
<dotml:edge from="EMail_Compound_History" to="EMail_Read" label="" fontname="Arial" fontsize="7" />
<dotml:edge from="EMail_Compound" to="EMail_Compose" label="EMAIL_COMPOSE" fontname="Arial" fontsize="7" />
<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>
<node id="10" label="left"/>
<node id="11" label="middle"/>
<node id="12" label="right"/>
</record>
<record>
<node id="20" label="one"/>
<node 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
Andreas