Subject: Re: [xsl] xsl transormation from flat tree to hierarchical tree From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Mon, 26 Mar 2012 11:34:59 -0400 |
<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 name="printStateTree" xmlns:dotml="http://www.martin-loetzsch.de/DOTML"> <xsl:param name="curState"/> <node id="{$curState/@name}" label="{$curState/@name}" fontname="Arial" fontsize="9"> <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> </node> </xsl:template>
<xsl:template match="state" mode="make-node"> <node id="{@name}" label="{@name}" fontname="Arial" fontsize="9"> <xsl:apply-templates mode="make-node" select="//state[@parent = current()/@name]" /> </node> </xsl:template>
Cheers, Wendell
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"> <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
-- ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xsl transormation from fl, Mukul Gandhi | Thread | RE: [xsl] xsl transormation from fl, Scott Trenda |
Re: [xsl] xsl transormation from fl, Mukul Gandhi | Date | RE: [xsl] xsl transormation from fl, Scott Trenda |
Month |