RE: testing for position of an element and displaying
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: 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
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format