 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 11th, 2006, 03:44 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Need information on xsl.param
I have declared the parameter in one template.
<xsl:template name="temp">
<xsl:param name="n" select="1"/>
</xsl:template>
Then in second template i want to use this param variable then
depending upon the condition i wanted ti change the value of this paramater.
<xsl:template match="/">
<xsl:call-template name="temp">
<xsl:with-param name="n" select="2"/>
</xsl:call-template>
<xsl:if test="$n=2">
<xsl:call-template name="temp">
<xsl:with-param name="n" select="3"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Is this correct way of sending values to parameter.depending on condition.
i am new to xslt.pls help me soon
sheetal
__________________
sheetal
|
|

September 11th, 2006, 03:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
That seems fine, you're not changing the parameter though, you're creating a new one that happens to have the same name. Parameters declared within templates are scoped to that template so don't clash with others that are template defined elsewhere.
--
Joe ( Microsoft MVP - XML)
|
|

September 11th, 2006, 04:49 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for replying.
Pls see the following code in java ..
int a[]={1,3,2,1,4,5,6,8,2,4,6,6};
for(int i=0;i<n;i++){
boolean flag=false;
if(i==0){
System.out.println(a[i]);
}else{
for(j=0;j<i;j++){
if(a[j]==a[i]){
flag=false;
j=i;
}else{
flag=true;
}
}
}
if(flag==true){
System.out.println(a[i]);
}
Same coding i wanted to implement in xslt.
<xsl:for-each select="/covis:root/polRq:PubsRestaurantsAndHotelsNBRq/Premises">
<xsl:variable name="flag" select="0"/>
<xsl:variable name="i" select="position()" />
<xsl:choose>
<xsl:when test="$i='1'">
<xsl:value-of select="./Trade/Code/ShortDescription" />
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="/covis:root/polRq:PubsRestaurantsAndHotelsNBRq/Premises">
<xsl:variable name="j" select="position()" />
<xsl:if test="$j < $i">
<xsl:choose>
<xsl:when test="/covis:root/polRq:PubsRestaurantsAndHotelsNBRq/Premises[$i]/Trade/Code/ShortDescription=/covis:root/polRq:PubsRestaurantsAndHotelsNBRq/Premises[$j]/Trade/Code/ShortDescription">
<xsl:variable name "$flag" select="1"/>
<xsl:variable name="j" select="$i" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="flag" select="1"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$flag"/>
</xsl:if>
</xsl:for-each>
<xsl:if test="$flag='1'">
<xsl:value-of select="/covis:root/polRq:PubsRestaurantsAndHotelsNBRq/Premises[$i]/Trade/Code/ShortDescription" />
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<br />
</xsl:for-each>
Here flag is variable which looses the scope once its comes out of loop..
If i declare the same variable as param variable then i may solve this problem but i am not getting how to use this param.
Depending upon on conditon i want to set value to variable then according to that variable i want to display result
sheetal
|
|

September 11th, 2006, 05:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Rather than try to force procedural code into a declarative language why not show your source XML and your desired output?
--
Joe ( Microsoft MVP - XML)
|
|

September 11th, 2006, 07:14 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is XML
<items>
<a>A</a>
<a>B</a>
<a>C</a>
<a>B</a>
<a>B</a>
<a>D</a>
<a>D</a>
<a>E</a>
</items>
i want to write xslt in such a way that it should display only unique value
EX:A,B,CD,E
sheetal
|
|

September 11th, 2006, 07:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
That looks the beginning of a grouping problem. If you're using XSLT 1.0 then something like:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="itemsByValue" match="items/a" use="." />
<xsl:template match="/">
<xsl:apply-templates select="items/a[generate-id() = generate-id(key('itemsByValue', .)[1])]">
<xsl:sort data-type="text" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="a">
<xsl:value-of select="."/><xsl:if test="position() != last()">,</xsl:if>
</xsl:template>
</xsl:stylesheet>
Take a look at this link for more complicated scenarios:
http://www.jenitennison.com/xslt/gro...muenchian.html
--
Joe ( Microsoft MVP - XML)
|
|

September 11th, 2006, 08:29 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank You..
Its working fine.
sheetal
|
|
 |