RE: [xsl] few nodes are missing ??

Subject: RE: [xsl] few nodes are missing ??
From: Dipesh Khakhkhar <dkhakhkh@xxxxxxxxxxxxxxx>
Date: Mon, 8 Sep 2003 16:36:16 -0400
Hi,

Thanks a lot Americo and Wendell for showing me once again how exactly I 
should approach the problem. I will try to be more specific in describing my 
problem. I was having good luck that Americo understood what exactly i wanted.

I implemented the Americo's verion. It almost does what i need it to do. This 
solution catches properly all the column names for all the tables. In this xsl 
I dont have absolute control for outputting headers for different tables.  I 
need control to appened few words before outputting headers for each table. 
Since i am writing this output which will go to database, here i am generating 
primary key and foreign key relationship using generate id. And as you must 
have made out the very first work i outputted is RootID.

You have made properly this for first node i.e. Root. I have made minor change 
in the xsl here to prepend "RootID" in front of Node1ID since Root and Node1 
are two different tables in my database.

Here is the modified xsl and my problem i have written in the one comment 
statement which will make it more clear i guess.

XSL
===


<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	version="1.0">
<xsl:output method="text"/>

<!-- sets the separator char, can change to whatever you want -->
<xsl:variable name="sep" select="&quot;&apos;&quot;"/>
<xsl:key match="@ColName" name="col" use="."/>
<!-- get unique global @ColName's -->
<xsl:variable name="cols"
select="//@*[generate-id()=generate-id(key('col',.))]"/>

<xsl:template match="Root">
<!-- Set the header -->
<xsl:value-of select="concat(name(),'ID')"/>
<xsl:apply-templates mode="headers" select="Node1[1] | @*"/>
<xsl:text>&#10;</xsl:text>
<!-- Start processing -->
<xsl:value-of select="generate-id()"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="Node1"/>
</xsl:template>

<!-- Headers -->
<xsl:template match="@*" mode="headers">
<xsl:value-of select="concat($sep,name())"/>
</xsl:template>
<xsl:template match="*" mode="headers">
<!-- Here i added RootID in front of Node1ID -->
<xsl:value-of select="concat($sep,name(..),'ID',$sep,name(),'ID')"/>
<xsl:apply-templates mode="headers" select="@*"/>
<xsl:value-of select="concat($sep,name(),'ID')"/>
<xsl:apply-templates mode="headers" select="*"/>
</xsl:template>
<xsl:template match="CLASS" mode="headers">
<xsl:value-of select="concat($sep,@Table,'ID')"/>
<xsl:apply-templates mode="headers" select="$cols"/>
</xsl:template>
<xsl:template match="@ColName" mode="headers">
<!-- Here after outputting 6 column headers for firsttable, I need to output 
Node1ID,SecondTableID(Parent(Foreign)key, Child(Private)key)  -->
<xsl:value-of select="concat($sep,.)"/>
</xsl:template>

<!-- Elements -->
<xsl:template match="@*">
<xsl:value-of select="concat($sep,.)"/>
</xsl:template>
<xsl:template match="Node1">
<xsl:if test="position()&gt;1">
<!-- if this is not the first Node1 then must fill with sep -->
<xsl:for-each select="../@*">
<xsl:value-of select="$sep"/>
</xsl:for-each>
</xsl:if>
<xsl:value-of select="concat($sep,generate-id(..),$sep,generate-id())"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="CLASS">
<xsl:value-of select="concat($sep,generate-id(..),$sep,generate-id())"/>
<xsl:apply-templates select="Row"/>
</xsl:template>
<xsl:template match="Row">
<xsl:variable name="cur" select="Column"/>
<xsl:if test="position()&gt;1">
<!-- if not the first Row then fill with sep according to ancestor and
their attributes -->
<xsl:for-each select="ancestor::*">
<xsl:value-of select="$sep"/>
<xsl:for-each select="@*">
<xsl:value-of select="$sep"/>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
<!-- here is where the work is done. For each unique copy the current
Column whose @ColName equals to unique(@ColName) -->
<xsl:for-each select="$cols">
<xsl:value-of select="concat($sep,$cur[@ColName=current()])"/>
</xsl:for-each>
<xsl:text>&#10;</xsl:text>
</xsl:template>
</xsl:stylesheet>

---------------------------------------------------------------------

My question here is i want to prepend few words after before outputting column 
names for each table. How do i do that ? Since from this xsl i don't come to 
know which table is ending where.

I hope you will get what I am stuck with.

Thanks once again for taking out your time for solving this problem.

Eagerly waiting for reply.

Regards,
Dipesh


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread