|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Node position and numbering.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="service">
<p>
<xsl:for-each select="step">
<xsl:number/><xsl:text>. </xsl:text><xsl:value-of
select="."/><xsl:if test="not(position() = last())"><br/></xsl:if>
</xsl:for-each>
</p>
</xsl:template>
</xsl:stylesheet>
produced
<p>1. Go to File menu<br/>
2. Select Print<br/>
3. Click Print</p>
Tested with Saxon 8.
Note that
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="service">
<p>
<xsl:apply-templates select="step"/>
</p>
</xsl:template>
<xsl:template match="step">
<xsl:number/><xsl:text>. </xsl:text><xsl:value-of select="."/><xsl:if
test="not(position() = last())"><br/></xsl:if>
</xsl:template>
</xsl:stylesheet>
produced exactly the same result (without processing the nodes other than
step nodes).
You don't have to account for every child node to use apply-templates.
Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)
c p <bugs75il@xxxxxxxxx>
05/05/2005 01:00 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc
Subject
Re: Node position and numbering.
Spencer,
Thats what I trying to explain in my email. That,
very unfortunately, I cannot do apply-templates on
<step> nodes. The biggest reason for not able to do
that is that I could have 100+ different possible
child nodes within <service> node and each child node
could potentially appear in any order. So I cannot do
apply-templates on specific child nodes as I would NOT
know what order I need to it in and second I'd have to
do 100 apply-templates for each child node.
I know its not the best XML design but heck thats what
I am handed down and I have to make it work. Not my
choice.
Thx,
C.
--- Spencer Tickner <spencertickner@xxxxxxxxx> wrote:
> Hi,
>
> I tried your above example with the match="service"
> followed by
> match="step" and got the desired output? Give this a
> try maybe it'll
> help:
>
> <?xml version='1.0'?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="service">
> <xsl:apply-templates select="step"/>
> </xsl:template>
>
> <xsl:template match="step">
> <xsl:value-of select="concat(position(), '. ',
> normalize-space(text()))"/><br/>
> </xsl:template>
> </xsl:stylesheet>
>
> output:
>
> 1. Go to File menu
> 2. Select Print
> 3. Click Print
>
> Sounds like you've tried this already, I know I've
> had this problem
> before and it has to do with whitespace nodes,
> either or give it a
> shot.
>
> On 5/5/05, c p <bugs75il@xxxxxxxxx> wrote:
> > Hello all,
> >
> > I have following XML:
> > -----------------------------------------
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <service>
> > <title>Printing the Page</title>
> > <somenode>node content might go
> here.</somenode>
> > <step>Go to File menu</step>
> > <step>Select Print</step>
> > <step>Click Print</step>
> > <somenode>you are all done.</somenode>
> > </service>
> >
> > -----------------------------------------
> > As you can see the XML has a <service> node with a
> > whole bunch of other child nodes. Out of all the
> > child nodes, I am interested in getting the
> position
> > for <step> nodes only. Its pretty simple but
> there's
> > a twist. In the example above if I did
> > <xsl:apply-templates match="service"/> and then
> for
> > each child node I did a position() then it would
> give
> > me numbers 2,4,and 5 for the <step> nodes.
> However
> > thats not what I want. I want it to give me
> numbers
> > 1,2,3 for the <step> nodes. The way I can get
> that is
> > by doing <xsl:apply-templates
> match="service/step"/>,
> > unfortunately due to the complexity of my XSL and
> XML
> > structure I cannot do that. Is there a way to
> achieve
> > this so I can get an output that will look like
> this:
> >
> > ---------------------------------------------
> > 1. Go to File menu
> > 2. Select Print
> > 3. Click Print
> > ---------------------------------------------
> >
> > Note: Its not always guaranteed that the first
> <step>
> > node will start after <title> node or any other
> node.
> > It could be random.
> >
> > Any help would be appreciated.
> >
> > Thx,
> > C
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
>
>
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
|
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
|

Cart








