Subject: RE: [xsl] testing for position of an element and displaying it accordingly From: ms <mina_hurray@xxxxxxxxx> Date: Mon, 22 Jan 2007 09:55:09 -0800 (PST) |
Hello: I have tried to implement this solution but I dont know where I am going wrong. Here is my complete code: This template is used for formatting. <xsl:template name="lists"> <xsl:param name="format"/> <fo:list-block> <fo:list-item> <fo:list-item-label> <xsl:choose> <xsl:when test="$format = '1'"> <fo:block> <fo:inline> <xsl:number format="1"/>.</fo:inline> </fo:block> </xsl:when> </xsl:choose> </fo:list-item-label> <fo:list-item-body start-indent="body-start()" end-indent="0pt"> <fo:block> <xsl:apply-templates> </xsl:apply-templates> </fo:block> </fo:list-item-body> </fo:list-item> </fo:list-block> </xsl:template> This template calls the above template for formatting: <xsl:template match="r1"> <xsl:if test="child::a"> <xsl:apply-templates select="a" mode="t"/> </xsl:if> <xsl:call-template name="lists"> <xsl:with-param name="format">1</xsl:with-param> </xsl:call-template> </xsl:template> This is the template for element a which is a child of <r1>. <xsl:template match="a" mode="t"> <fo:block space-before="6pt"> <fo:inline><xsl:value-of select="."/> </fo:block> </xsl:template> <xsl:template match="a"> <fo:block space-before="6pt"> <fo:inline><xsl:value-of select="."/> </fo:block> </xsl:template> <xsl:template match="text"> <fo:block space-before="6pt"> <fo:inline><xsl:apply-templates/> </fo:block> </xsl:template> And my Input is: <r1> <a>test</a> <a>test2</a> <text>test test</text> <a>test3</a> </r1> My desired output is: test test2 1. test test test3 The reason for checking if <a> is a child of <r1> and applying the mode is so that this <a> appears above <r1> without getting formatted as 1. test So even though <r1> element is formatted to be 1., any <a> element which appear immediately after <r1> should not be formatted. If there is an <a> element after some other element like in this example <text>, then it should be displayed as it is in the document tree. Please let me know if this is clear and if there is a way to do it and if there is amistake in my code. --- ms <mina_hurray@xxxxxxxxx> wrote: > Hello: > > I did see the axis specifier thread on this list, > unfortunately it is not me, but I am facing a > similar > issue. I tried to implement the solutions given in > those, but I was not successful and thats te reason > for posting this issue. > > > --- Michael Kay <mike@xxxxxxxxxxxx> wrote: > > > > > I assume you're the same person as xslt.new who > > posted "axis specifiers" > > last week (if not, it's a remarkable that you have > > exactly the same problem > > and the same misunderstandings). > > > > We need to go back a step. You haven't understood > a > > word of the explanations > > we gave you last week. Giving you the same > > explanations again isn't going to > > do much good. I'm really trying hard to read your > > postings and work out > > which step in the learning process you've got > stuck > > on, but I'm struggling. > > > > The normal way of processing an XML document is to > > work top-down. First, you > > have to think of the document as a tree, with the > > root at the top (strange > > in botany, but not in computing). The document > node > > itself is at the top, > > then the r1 element, and (a,a,b,a) are below the > r1 > > element, at the next > > level down (I stress this because you talk of > test3 > > as being "below" b, > > which means you're not yet thinking in tree > terms). > > So top down processing > > means you write a template rule for r1, which > > typically applies templates to > > each of its children. You then define template > rules > > for each kind of child. > > > > This works when the rules for an element are > > independent of where it appears > > relative to other elements at the same level. For > > example, if every a > > element is processed by converting the <a> tag to > a > > <p>, then you can write > > a template rule > > > > <xsl:template match="a"> > > <p><xsl:apply-templates/></p> > > </xsl:template> > > > > Similarly, if every b is processed by outputting a > > <p> but with a sequence > > number attached, you can write > > > > <xsl:template match="b"> > > <p><xsl:number/>: <xsl:apply-templates/></p> > > </xsl:template> > > > > Now, your input and your processing seems to > follow > > this conventional style. > > As far as we can see, you've got a perfectly > > straightforward easy > > transformation to do here that yields to the basic > > techniques in chapter 1 > > of any textbook, and we can't see why you're > making > > it so difficult. > > > > Michael Kay > > http://www.saxonica.com/ > > > > > > > > > -----Original Message----- > > > From: ms [mailto:mina_hurray@xxxxxxxxx] > > > Sent: 19 January 2007 14:58 > > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > > Subject: [xsl] testing for position of an > element > > and > > > displaying it accordingly > > > > > > Hi all: > > > > > > My input XML looks like this; > > > > > > <r1> > > > <a>test</a> > > > <a>test2</a> > > > <b>test test</b> > > > <a>test3</a> > > > </r1> > > > > > > For this XML, I would like to write an XSLT > which > > basically > > > achieves the following: > > > > > > 1) For the <a> elements which are above the <b> > > element, they > > > should be displayed this way: > > > > > > Test > > > Test2 > > > 1)test test > > > > > > 2) For the <a> element which appears after the > <b> > > element, I > > > want it displayed after the <b> element: > > > > > > Test > > > Test2 > > > 1)test test > > > test3 > > > > > > How can I achieve this in XSLT? I tried testing > > the > > > position, using position()=1. This works > obviously > > for the > > > first <a> element and fails for the second one. > > > > > > Please let me know if this is possible? > > > > > > > > > > > > > > > ______________________________________________________________ > > > ______________________ > > > Do you Yahoo!? > > > Everyone is raving about the all-new Yahoo! Mail > > beta. > > > http://new.mail.yahoo.com > > > > > > > > > ____________________________________________________________________________________ > Need a quick answer? Get one in minutes from people > who know. > Ask your question on www.Answers.yahoo.com > > ____________________________________________________________________________________ Yahoo! Music Unlimited Access over 1 million songs. http://music.yahoo.com/unlimited
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] testing for position of a, ms | Thread | Re: [xsl] testing for position of a, Mark Carlson |
Re: [xsl] <xsl:copy-of> question, David Carlisle | Date | Re: [xsl] testing for position of a, Mark Carlson |
Month |