XSL ... two templates ?

Discussion in 'XML' started by Alan Searle, Jan 4, 2006.

  1. Alan Searle

    Alan Searle Guest

    I have some XML/XSL web pages which display data grids (stored in XML
    and formatted by the XSL file). This works fine.

    However, I would like to retrieve an item of text from the grid (one
    particular column which will later be removed from the display) and show
    this as a main title for the page (i.e. the title will vary depending on
    the grid that is opened).

    The result should look like this:

    Region: London

    Month Sales Sales Person
    Jan 4345 John
    Jan 8494 Sue
    Jan 7849 Peter

    The grid works fine but I am having trouble plucking the title (in this
    case 'London') out of the XML file for prior display.

    I believe that I need to declare two templates (i.e. one for the title
    and one for the grid) but am really not sure how to do this.

    Does anyone have an idea? Or maybe a suggestion for an alternative
    technique?

    Any tips or recommendations of tutorials would be a great help.

    Many thanks,
    Alan Searle

    PS: Remove the xxx in the e-mail to send me a message
     
    Alan Searle, Jan 4, 2006
    #1
    1. Advertising

  2. Alan Searle wrote:

    > However, I would like to retrieve an item of text from the grid (one
    > particular column which will later be removed from the display) and show
    > this as a main title for the page (i.e. the title will vary depending on
    > the grid that is opened).


    What you need to do depends on the input XML, in terms of XSLT all you
    need to do is put a literal result title element with e.g.
    <title><xsl:value-of select="/element/child1/child2/child" /></title>
    at the proper place where the title element belongs in HTML. That XPath
    expression as the select attribute value of course needs to be written
    according to which element you want to select in your XML but as you
    haven't bothered to share your XML that is all we can suggest.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 4, 2006
    #2
    1. Advertising

  3. Alan Searle

    Alan Searle Guest

    Hi Martin,

    Thanks for your tip ...

    >> However, I would like to retrieve an item of text from the grid (one
    >> particular column which will later be removed from the display) and
    >> show this as a main title for the page (i.e. the title will vary
    >> depending on the grid that is opened).

    >
    > What you need to do depends on the input XML, in terms of XSLT all you
    > need to do is put a literal result title element with e.g.
    > <title><xsl:value-of select="/element/child1/child2/child" /></title>
    > at the proper place where the title element belongs in HTML.


    This sounds like exactly what I need but I gave it a try and couldn't
    get it to display. That's a shame.

    > That XPath
    > expression as the select attribute value of course needs to be written
    > according to which element you want to select in your XML but as you
    > haven't bothered to share your XML that is all we can suggest.


    Sorry about not sending the XML. Below are excerpts from the XML and
    XSL files (I want to display the 'LangFrom' field in the title) ...

    Excerpt from XML ...
    --------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet href="OpenJobs.xsl" type="text/xsl"?>
    <dataroot>
    <job>
    <job_id>8029</job_id>
    <Status>A</Status>
    <job_Title>Report 2005</job_Title>
    <Action_pers>Hansen, M</Action_pers>
    <LangFrom>EN</LangFrom>
    <LangInto>DA</LangInto>
    <job_Pages>0.5</job_Pages>
    </job>
    <job>
    <job_id>7948</job_id>
    <Status>C</Status>
    <job_Title>Update of OrgaChart</job_Title>
    <Action_pers>Hald, B</Action_pers>
    <LangFrom>EN</LangFrom>
    <LangInto>DA</LangInto>
    <job_Pages>1</job_Pages>
    </job>
    </dataroot>

    Excerpt from the XSL ...
    ------------------------
    ....
    <xsl:template match="dataroot">
    <html>
    <head>

    <script language="JavaScript" type="text/javascript">
    ... some javascript here
    </script>

    </head>
    <body>
    <h1>Language: <xsl:value-of select="/job/LangFrom" /></h1>

    <table width="95%" border="1">
    <tr bgcolor="#dddddd" VALIGN="TOP">
    <td class="head" onclick="sort('job_id');">Job</td>
    <td class="head" onclick="sort('Status');">On Hold</td>

    Code goes on to display the grid in this table ...
    -------------------------

    Maybe you have an idea why this isn't working?

    And I was wondering if I need to include an 'apply-template' statement
    too? e.g. <xsl:apply-templates select="job">

    Thanks very much for your help.

    Regards,
    Alan Searle
     
    Alan Searle, Jan 4, 2006
    #3
  4. Alan Searle

    Alan Searle Guest

    Yippeee ...

    Hi Martin,

    I played around with your idea ...

    >> What you need to do depends on the input XML, in terms of XSLT all you
    >> need to do is put a literal result title element with e.g.
    >> <title><xsl:value-of select="/element/child1/child2/child" /></title>
    >> at the proper place where the title element belongs in HTML.


    .... adapted it a little ...

    <xsl:apply-templates select="/dataroot/job[1]/LangFrom" />

    .... and got it working. I'm very pleased.

    Indeed, at first it displayed the header multiple times but then I added
    'job[1]' to limit it to the first record and it was fine.

    Thanks for your tips: You put me on the right track!

    Regards,
    Alan
     
    Alan Searle, Jan 4, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sparko
    Replies:
    0
    Views:
    418
    Sparko
    Jul 9, 2004
  2. Vijay singh
    Replies:
    1
    Views:
    450
    Martin Honnen
    Nov 4, 2004
  3. Replies:
    1
    Views:
    3,653
    A. Bolmarcich
    May 27, 2005
  4. JKop
    Replies:
    3
    Views:
    505
  5. recover
    Replies:
    2
    Views:
    844
    recover
    Jul 25, 2006
Loading...

Share This Page