Newbie in XSLT need help

Here should go questions about transforming XML with XSLT and FOP.
akaii
Posts: 4
Joined: Fri Mar 03, 2006 11:10 am

Newbie in XSLT need help

Post by akaii » Fri Mar 03, 2006 11:18 am

Hey
I'm new in xslt and I'm blocked on the following problem hope somebody can help.
I'm checking my xml file in my xsl sheet to have two variables (oldgroup and isactive) in my aspx page but I'm not getting the result I'm waiting. Here is my xml file:

Code: Select all

- <user cn="KRATEL Carsten" guid="5ff813dbe909d31183c900903306039e" e164="410" h323="Chambre 141" pwd="********" hw-id="IP202-0a-01-97" busy-out="1" loc="EMS_EP" filter="un" cd-filter="unknown" type="ep">
<grp name="Central" mode="active" />
<grp name="Chambres" />
<grp name="all" />
<gw name="GW-DECT" dsp="Carsten Kratel" ipei="00077 0777777" />

Code: Select all

 <xsl:if test="@name=//show/user[@cn=$user]/grp/@name">
<input type="hidden" name="oldgroup">
<xsl:attribute name="value">
<xsl:value-of select="@name"/>
</xsl:attribute>
</input>
<xsl:choose>
<xsl:when test="@mode='active'">
<input type="hidden" name="isactive">
<xsl:attribute name="value">
<xsl:value-of select="//show/user[@cn=$user]/grp/@mode"/>
</xsl:attribute>
</input>
</xsl:when>
<xsl:otherwise>
<input type="hidden" name="isactive">
<xsl:attribute name="value">
<xsl:value-of select="'notActive'"/>
</xsl:attribute>
</input>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
In my isactive variable I always get "notActive","notActive","active" but I should get "active","notActive","notActive" so what's wrong?

akaii
Posts: 4
Joined: Fri Mar 03, 2006 11:10 am

Post by akaii » Fri Mar 03, 2006 5:11 pm

Somebody here ?

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Mon Mar 06, 2006 3:41 pm

Hello,

The variable $user and the transformation output cannot be determined from your post. Please post a reduced sample of the transformation input files which show the problem, the current output obtained in <oXygen/> and the expected output. Also specify other transformation scenario parameters set in <oXygen/> which you think are useful in debugging the problem, for example stylesheet parameters, if you set such parameters.

Regards,
Sorin

akaii
Posts: 4
Joined: Fri Mar 03, 2006 11:10 am

Post by akaii » Mon Mar 06, 2006 5:57 pm

here is the output I have

Code: Select all

<td colspan="2" height="20">
<input type="hidden" name="oldgroup" value="Deux">
<input type="hidden" name="isactive" value="active">
<input type="hidden" name="newgroup" value="Deux">
<input type="hidden" name="oldgroup" value="Un">
<input type="hidden" name="isactive" value="active">
<input type="hidden" name="newgroup" value="Un">
<input type="hidden" name="oldgroup" value="all">
<input type="hidden" name="isactive" value="active">
<input type="hidden" name="newgroup" value="all">
<input type="hidden" name="oldgroup" value="Central">
<input type="hidden" name="isactive" value="">
<input type="hidden" name="newgroup" value="Central">
<input type="hidden" name="oldgroup" value="Chambres">
<input type="hidden" name="isactive" value="">
<input type="hidden" name="newgroup" value="Chambres">
</td>
Datas are picked up from the xml file:

Code: Select all

- <user cn="KRATEL Carsten test" guid="5ff813dbe909d31183c900903306039e" e164="410" h323="Chambre 141" pwd="********" hw-id="IP202-0a-01-97" busy-out="1" loc="EMS_EP" filter="un" cd-filter="unknown" type="ep">
<grp name="Central" mode="active" />
<grp name="Chambres" mode="active" />
<grp name="Deux" mode="active" />
<grp name="Un" mode="active" />
<grp name="all" mode="active" />
- <user cn="OSPEL Marcel" guid="e018ed8ce909d31183c900903306039e" e164="510" h323="Chambre 410" cfnr="45" busy-out="2" loc="EMS_NB" filter="deux" cd-filter="unknown" gi="all" type="ep">
<grp name="Central" />
<grp name="Chambres" />
the xsl shee (part of it tell me if you need the whole):

Code: Select all

 <xsl:template match="grp">
<xsl:if test="not(@name=following::grp/@name)">
<xsl:choose>
<xsl:when test="$mode='advanced'">
<tr>
<xsl:if test="0 mod 2 = 0">
<xsl:attribute name="style">background-color: #eeeeee</xsl:attribute>
</xsl:if>
<td align="center">
<xsl:if test="@name=//show/user[@cn=$user]/grp/@name">
<input type="hidden" name="oldgroup">
<xsl:attribute name="value">
<xsl:value-of select="@name"/>
</xsl:attribute>
</input>
<input type="hidden" name="isactive">
<xsl:attribute name="value">
<xsl:value-of select="@mode"/>
</xsl:attribute>
</input>
</xsl:if>
<input type="checkbox" name="newgroup">
<xsl:attribute name="value">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:if test="@name=//show/user[@cn=$user]/grp/@name">
<xsl:attribute name="checked" />
</xsl:if>
</input>
</td>
<td>
<xsl:value-of select="@name"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@name=//show/user[@cn=$user]/grp/@name">
<input type="hidden" name="oldgroup">
<xsl:attribute name="value">
<xsl:value-of select="@name"/>
</xsl:attribute>
</input>
<input type="hidden" name="isactive">
<xsl:attribute name="value">
<xsl:value-of select="@mode"/>
</xsl:attribute>
</input>
</xsl:if>
<xsl:if test="@name=//show/user[@cn=$user]/grp/@name">
<input type="hidden" name="newgroup">
<xsl:attribute name="value">
<xsl:value-of select="@name"/>
</xsl:attribute>
</input>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
What I could notice was the oldgroup variable is filled with "Deux" "Un" "all" datas from the user "KRATEL Carsten" (which is the right values) but I don't why the last datas are taken from the user "OSPEL Marcel" "Central" "Chambres". I block on this since thursday last would be nice if you could help me I didn't write this code and the guy is not working in my company anymore whatismore I new in xslt.

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Mon Mar 06, 2006 6:06 pm

Did you try to debug the transformation in <oXygen/> and place breakpoints inside the xsl:template with the match="grp" attribute ?

Regards,
Sorin

akaii
Posts: 4
Joined: Fri Mar 03, 2006 11:10 am

Post by akaii » Mon Mar 06, 2006 6:28 pm

no my boss didn't want to buy Oxygen he says it's too expensive for our company (we are a little company)

jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung » Wed Mar 08, 2006 1:01 am

Just as a clarification
You're using:
<xsl:if test="not(@name=following::grp/@name)">

Which means if this is the last grp node in the FILE that has this name. Did you want the last node in the file, or did you want the first node, or maybe just the last node in this user?

You may want (for first node in file with this name)
<xsl:if test="not(@name=preceding::grp/@name)">

or if you want within each user node, you may want
<xsl:if test="not(@name=following-sibling::grp/@name)">
or
<xsl:if test="not(@name=preceding-sibling::grp/@name)">

Post Reply