SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie XML questions

    Hi guys, hope you can help me out with a couple of simple queries.

    1 - I have a field named date, and have set the XSL file to order by date descending. It does order the records of sorts e.g

    23/06/03
    16/04/03
    10/07/03

    What is is doing is taking the first set of numbers it encounters, is there something to sort by date?

    2 - Hyperlinks, how can I create a hyperlink like in HTML?

    Cheers

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whats your current XSL Stylesheet ?

    As to creating links they are very easy to do... If I can remember where I put my last Stylesheet I'll post it for you to see the transformation.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the XSL Stylesheet

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    - <xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform">
    - <xsl:template match="/">
    - <html>
    - <body>
    - <xsl:for-each select="news/item">
    <xsl:sort select="date" order="descending" />
    - <table>
    - <tr>
    - <td>
    <xsl:value-of select="date" />
    </td>
    </tr>
    - <tr>
    - <td>
    <xsl:value-of select="content" />
    </td>
    </tr>
    </table>
    </xsl:for-each>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use substring sorts - see here and adapt for your date format...
    http://www.topxml.com/stylesheetcent...DataType=SSCFS
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that link, I will have a look later on.

    Any ideas on the link problem?

  6. #6
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With regard to your second question, it depends what the input for the hyperlink looks like, but ultimately you'll be wanting to do something like this:

    Code:
    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:value-of select="url" />
      </xsl:attribute>
      <xsl:value-of select="text" />
    </xsl:element>
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for bearing with me, I am still struggling a little.

    Here is a sample of the XML doc, where I am referring to the link.

    <item>
    <date>10/06/03</date>
    <content>
    New work with <url><a href="http://www.ultraview.co.uk">Ultraview Solutions</a></url> - Corporate Identity &amp; Web Development for new IT security and workflow company
    </content>
    </item>

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm... Nope; What you have now done is put valid HTML ie the actual HREF link in your XML document; it simply doesn't work like that.

    What you're looking to put in your XML document is this, based on the posted XSL template match:

    PHP Code:
    .
    .
    <
    a>
    <
    url>Your URL Goes Here</url>
    <
    text>Your Link Text Goes Here</text></a>
    .

    Then your XSL stylesheet with match the pattern ie A and then transform this to your HREF link if you see ?

  9. #9
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my XSL template what I use to transform a A HREF Link:

    PHP Code:
    .
    .
    <
    xsl:template match="link">
    - <
    a>
    - <
    xsl:attribute name="href">
      <
    xsl:value-of select="@href" /> 
      </
    xsl:attribute>
      <
    xsl:value-of select="." /> 
      </
    a>
      </
    xsl:template>
    .

    And the XML:

    PHP Code:
    .
    .
    <
    link href='www.mysample.com'>Click Me</link>
    .

    Simple really ? Once you understand the relationship between XML and XSL-T;

  10. #10
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Halifax
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code is exactly what I'm after.

    Now my next problem, how do I then integrate this in to my existing stylesheet?

    I can't get the code to work, so no link is displayed or the date, content, and link are all highlighted.

    Arrrgghhh


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •