RE: [xsl] can a value of a parameter depends on a other value

Subject: RE: [xsl] can a value of a parameter depends on a other value
From: John Wilkinson <jwilkinson@xxxxxxxxxxx>
Date: Wed, 30 Nov 2011 11:30:15 -0600
That's a lot clearer.  Below is an XSLT 1.0 stylesheet that (I think) does
what you want.  The stylesheet itself just copies the input through to the
output, recursing through all elements and explicitly copying whatever it
finds.  It could be improved in XSLT 2.0 (probably even in 1.0), but it is
what I have handy.

John

=============================================================

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://tsystem.com/ev2";>
	<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"
encoding="Windows-1252"/>

	<xsl:param name="month"/>
	<xsl:param name="page"/>

	<!-- For later use -->
	<xsl:param name="totalpages"/>
	<xsl:param name="offset"/>


	<xsl:variable name="articlesperpage">
		<xsl:choose>
			<xsl:when test="($month = '2005-02') and (number($page) = 1)">2</xsl:when>
			<xsl:when test="($month = '2005-02') and (number($page) = 2)">3</xsl:when>
		</xsl:choose>
	</xsl:variable>

	<!-- Using the variable -->
	<xsl:template name="EmitArticles">
		<xsl:choose>
			<xsl:when test="number($articlesperpage) = 3">
				<!-- Emit three articles. -->
			</xsl:when>
			<xsl:when test="number($articlesperpage) = 2">
				<!-- Emit two articles. -->
			</xsl:when>
				<!-- Emit one article? -->
			<xsl:otherwise>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="/">
		<xsl:copy>
			<xsl:apply-templates select="* | @* | comment()"/>
		</xsl:copy>
	</xsl:template>

	<xsl:template match="@*">
		<xsl:copy-of select="."/>
	</xsl:template>

	<!-- Remove the Stylus Studio metadata, if it is present. -->
	<xsl:template match="comment()[contains (.,'Stylus Studio
meta-information')]">
	</xsl:template>

	<xsl:template match="comment()">
		<xsl:copy-of select="."/>
	</xsl:template>

	<xsl:template match="*">
		<xsl:choose>
			<xsl:when test="./*">
				<xsl:copy>
					<xsl:apply-templates select="* | @* | comment()"/>
				</xsl:copy>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>

========================================================

-----Original Message-----
From: Roelof Wobben [mailto:rwobben@xxxxxxxxxxx]
Sent: Wednesday, November 30, 2011 11:09 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] can a value of a parameter depends on a other value



What am trying to make is a blog which dived into months.

Some months have so many articles that I have to divide them into pages.

The problem is that I want to decide how many articles are placed on a
particular place.



So i want to make a parameter articlesperpage which value depends on the value
of the parameters month and page.

The parameters month and page are made by the cms I use. That's Symphony cms.



So in pseudoocode I want this.



If month="2005-02" and page=1 then articlesperpage must be 2

if month="2005-02" and page=2 then articlesperpage must be 3



Later on I also need the parameters totalpages and offset.

Totalpages is the total of pages of a month. I need it because later on I will
write a prev/next script.

Offset is the number of articles which must not be displayed because the
articles are displayed on a earlier page.



But first I want to make it work with one parameter and I try to find out how
to make this work.



Roelof






----------------------------------------
> Date: Wed, 30 Nov 2011 14:10:10 +0000
> From: mike@xxxxxxxxxxxx
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] can a value of a parameter depends on a other value
>
> On 30/11/2011 11:02, Roelof Wobben wrote:
> > Oke,
> >
> >
> >
> >
> >
> > The whole xslt looks like this :
> >
> >
> >
> >
> > I hope I now give enought clues to solve this.
> >
> >
>
> We can now see exactly what's wrong, but we can't help you to fix it,
> because we have no idea what you are trying to achieve.
>
> Michael Kay
> Saxonica

This e-mail message and any attachment(s) transmitted with it are intended
only for the
use of the recipient(s) named above.This message may be privileged and/or
confidential.
If you are not an intended recipient, you may not review, copy or distribute
this message.
If you have received this communication in error, please notify us immediately
by e-mail
and delete the original message.

Current Thread