Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help for XSL transformation

Status
Not open for further replies.

buzz1234

Programmer
Jan 7, 2010
3
FR
Here is the xml file I have to customize

<?xml version="1.0"?>
<CfgExpression xsi:schemaLocation="urn:com:das:conf CfgDef.xsd" xmlns:xsi=" xmlns="urn:com:das:conf">
<Description>
<Characteristic Description="desc Equipment" Id="1" Name="Equipment">
<Characteristic Description="desc Middle equipment" Id="2" Name="Middle"/>
<Characteristic Description="desc Luxe equipment" Id="3" Name="Luxe"/>
<Characteristic Description="desc Basic equipment" Id="4" Name="Basic"/>
</Characteristic>
<Characteristic IsExclusive="true" Description="desc Engine" Id="5" Name="Engine">
<Characteristic Description="desc V6 engine" Id="6" Name="V6"/>
<Characteristic Description="desc V12 engine" Id="7" Name="V12"/>
</Characteristic>
</Description>
<Expression>
<AND>
<OR>
<EffectivityRef Id="2" Name="35827.1"/>
<EffectivityRef Id="1" Name="35828.1"/>
</OR>
<OR>
<AND>
<Characteristic Id="5" Name="Engine">
<Characteristic Id="6" Name="V6"/>
</Characteristic>
<Characteristic Id="1" Name="Equipment">
<Characteristic Id="4" Name="Basic"/>
</Characteristic>
</AND>
<AND>
<Characteristic Id="5" Name="Engine">
<Characteristic Id="7" Name="V12"/>
</Characteristic>
<Characteristic Id="1" Name="Equipment">
<Characteristic Id="3" Name="Luxe"/>
</Characteristic>
</AND>
</OR>
</AND>
</Expression>
</CfgExpression>


here is the following xsl file I use to customize it :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl=" xmlns:fo=" xmlns:xsi=" xmlns:xs=" xmlns:fn=" xmlns:cfg="urn:com:das:conf">
<xsl:eek:utput method="text"/>

<!-- template CfgExpression -->
<xsl:template match="cfg:CfgExpression">
<xsl:for-each select="cfg:Expression">
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>
<!-- template Expression -->

<!-- template Description -->
<xsl:template name="Description">
<xsl:apply-templates/>
</xsl:template>

<!-- template AND -->
<xsl:template match="cfg:AND">
<xsl:for-each select="*">
<xsl:if test="position() != 1">
<xsl:text> ; </xsl:text>
</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>

<!-- template OR -->
<xsl:template match="cfg:OR">
<xsl:for-each select="*">
<xsl:if test="position() != 1">
<xsl:text> | </xsl:text>
</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>

<!-- template Caracteristic -->
<xsl:template match="cfg:Characteristic">
<xsl:value-of select="@Name"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="cfg:Characteristic/@Name"/>
<xsl:text/>
</xsl:template>

<!-- template EffectivityRef -->
<xsl:template match="cfg:EffectivityRef">
<xsl:text>[</xsl:text>
<xsl:value-of select="@Name"/>
<xsl:text>] </xsl:text>
</xsl:template>

</xsl:stylesheet>



The result I have today :

[35827.1] | [35828.1] ; Engine,V6 ; Equipment,Basic | Engine,V12 ; Equipment,Luxe

what I would like to have :

[35827.1] | [35828.1] ; Engine,V6 ; Equipment{Basic} | Engine,V12 ; Equipment{Luxe}

the display of “{ }“ or “,” is depend of the value of ”IsExclusive” available in the <Description> part

with another xsl file I would like to have :

Engine,desc V6 Engine; Equipment{desc Basic equipment} | Engine,desc V12 Engine; Equipment{desc Luxe equipment}

in that case I would like to by pass EffectivityRef and its AND and OR associated above

please I need help for that
does someone has an idea ?
Ludovic
 
[1] The simplest solution is to look up the matching data.
[tt]
<!-- template Caracteristic -->
<xsl:template match="cfg:Characteristic">
[blue]<xsl:variable name="isexclusive">
<xsl:choose>
<xsl:when test="/cfg:CfgExpression/cfg:Description/cfg:Characteristic[@Id=current()/@Id]/@IsExclusive='true'">
<xsl:value-of select="'true'" />
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="'false'" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>[/blue]
<xsl:value-of select="@Name"/>
[blue]<xsl:if test="$isexclusive='true'">
<xsl:value-of select="concat(',',cfg:Characteristic/@Name)"/>
</xsl:if>
<xsl:if test="$isexclusive='false'">
<xsl:value-of select="concat('{',cfg:Characteristic/@Name,'}')"/>
</xsl:if>[/blue]
<xsl:text/>
</xsl:template>
[/tt]
[2] Now some detail. Since you've Characteristic elements all over the places, it may be necessary to make the template more precise in the matching, namely, for those Characteristic which parent is AND only.
<xsl:template match="cfg:Characteristic">
[tt]<xsl:template match="[blue]cfg:AND/[/blue]cfg:Characteristic">[/tt]
For the moment, the problem is not surfaced because only those Characteristic are actually having a chance to be matched.
 
thanks a lot for the answer

any idea for the second question :

with another xsl file I would like to have :

Engine,desc V6 Engine; Equipment{desc Basic equipment} | Engine,desc V12 Engine; Equipment{desc Luxe equipment}

in that case I would like to by pass EffectivityRef node and its AND and OR associated above
 
[3]
>in that case I would like to by pass EffectivityRef node and its AND and OR associated above
One way to do it is to change the xsl:for-each line in the template AND.
[tt]
<!-- template AND -->
<xsl:template match="cfg:AND">
<xsl:for-each select="*[blue][count(descendant::cfg:EffectivityRef)=0][/blue]">
<xsl:if test="position() != 1">
<xsl:text> ; </xsl:text>
</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
[/tt]
[3.1] The remaining part's formatting, you've to do it yourself with the same approach I've shown you in [1].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top