xsl-list
[Top] [All Lists]

RE: [xsl] testing for position of an element and displaying it accordingly

2007-01-19 09:15:10

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(_at_)yahoo(_dot_)com] 
Sent: 19 January 2007 14:58
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>