Subject: Re: [xsl] does an element have a unique id?, and a problem to solve From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 16 Aug 2002 12:50:11 +0100 |
Hi Thomas, > 1) how to specifiy parameter in XSLT in Cocoon so that it works also > when no parameter is given; I've added: > > <map:match pattern="*/*-*"> > <map:generate src="content/{1}/{2}.xml"/> > <map:transform src="transforms/inners.xsl"> > <map:parameter name="param" value="{3}"/> > <map:parameter name="css-stylesheet" value="default.css"/> > </map:transform> > <map:serialize type="html"/> > </map:match> > > so, it works when there is a "*/*-1" but comes to an error when > typing "*/*", however I would like to declare in XSL that if there > is no param ("-*"), use the first <content/>. I don't know how to > make it work this way. (???) I'm a little rusty on Cocoon, but what about having a separate match like: <map:match pattern="*/*"> <map:generate src="content/{1}/{2}.xml" /> <map:transform src="transforms/inners.xsl"> <map:parameter name="param" value="1" /> <map:parameter name="css-stylesheet" value="default.css" /> </map:transform> </map:match> Put this *after* the match you already have, as it's a more general pattern and Cocoon uses the first available match. Or perhaps you can use the regexp URI matcher rather than the wildcard URI matcher? > 2) I've tried to use the postion() for specifing the parameter to > render with the special formating as follows: > > <xsl:for-each select = "content[position() != $firstcontent]"> > <xsl:if test = "position() mod 2 = 0"> > <p/><h3><xsl:value-of select="header1"/></h3> > <xsl:value-of select="concat(substring-before(para, '.'), > '.')"/> <a href="{position()}" class="navigators">»</a> > </xsl:if> > </xsl:for-each> > > but in case of $firstcontent=2 the for-each will not list it, and > position will start from 1, so position() doesn't show the original > listed id/position as it is in the XML doc. Beyond adding an > attribute to the element in the XML for specifing a unique > identifier, is there something else how I can find out the original > XML content position number? You could use xsl:number to give you the position, or calculate it by counting the number of preceding sibling content elements there are and adding 1: count(preceding-sibling::content) + 1 > What's make it hard, so that a simple for-each for only "content" > won't work, is that I have 2 columns, and if I use only the content > for-each list and display every odd and even position(), than incase > of a $firstcontent=2 and having 5 <content/> the first column will > have pos:1,3,5 and the second column will have pos: 4, but what I'd > like to show is that every second <content/> goes to the same column > => column1 will have: pos:1, 4 and column2 will have pos: 3,5. Sure. I think that the above will work fine if you use the count() to give you the number-amongst-all-content elements and position() to give you the position to determine where it should go in the table. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] does an element have a unique, Thomas Sandor | Thread | [xsl] local variable problem...agai, aruniima . chakrabar |
Re: [xsl] built in templates questi, Jeni Tennison | Date | [xsl] local variable problem...agai, aruniima . chakrabar |
Month |