p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2006, 07:39 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting a heading only in only the first element

I would like to insert a heading for the first child element in another element, and not for any others that may follow. For example, if I have XML like this:
--------------------------------------

<article>
    <section>
        <information>
        some stuff
        </information>

        <question>
        one
        </question>

        <question>
           two
        </question>

    </section>

    <section>
        <information>
        some stuff
        </information>

        <question>
        three
        </question>

        <question>
            four
        </question>

    </section>

</article>
-----------------------------------

And my XSLT looks something like this:

------------------------------------

    <xsl:template match="/">
    <html>
        <head>
            <title></title>

        </head>
        <body>
        <xsl:apply-templates/>

        </body>
    </html>
</xsl:template>

<xsl:template match="information">
<b><xsl:apply-templates/></b>
</xsl:template>

<xsl:template match="question">
<h3>Test My Knowledge</h3>
<h4>Question <xsl:number level="any"/></h4>

</xsl:template>

</xsl:stylesheet>
------------------------------------

Then I get the following result:

------------------------------------

some stuff
Test My Knowledge
Question 1
Test My Knowledge
Question 2
some stuff
Test My Knowledge
Question 3
Test My Knowledge
Question 4
--------------------------------------

But I would like the "Test my Knowledge" to apeear only in front of the first "question" element in every "section" element, something like this:

----------------------------------------

some stuff
Test My Knowledge
Question 1
Question 2

some stuff
Test My Knowledge
Question 3
Question 4

---------------------------------------

Is it possible to do this without changing the structure of the XML?








Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 22nd, 2006, 08:04 AM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

Since you want the heading output once for each information element, just change your code to produce it as part of the template that processes information elements.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old September 28th, 2006, 09:06 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Stekker,

I used this syntax to pick out the first entry ...

<xsl:apply-templates select="/dataroot/xmlout[1]/REPTITLE" />

REPTITLE is a field containing the title of the report and [1] tells the processor to take just the first occurance (I believe).

Hope this helps you :-)

Cheers,
Alan.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting/Creating element in order whelanm XSLT 3 August 14th, 2008 01:54 PM
display no heading if null oleafo ASP.NET 1.0 and 1.1 Basics 1 January 8th, 2007 06:23 PM
inserting element wihout template match gonzalocordero XSLT 2 July 3rd, 2006 01:46 PM
Cannot Modigy Heading wongcalvin Beginning PHP 1 December 12th, 2004 11:05 PM
Inserting one element into another srini XSLT 3 January 21st, 2004 08:09 AM



All times are GMT -4. The time now is 02:18 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc