Jump to content

XSLT transformation for newspage [SOLVED]


Recommended Posts

I've got an XML question. Or rather, an XSL(T) question.

 

This is the XML:

 

<nieuwslijn>

<artikel id="1">
<titel>de nieuwslijn</titel>
<datum>25 november 2004</datum>
<inhoud>Dienstregelingen en wedstrijd oudejaarsnacht beschikbaar vanaf 6 december</inhoud>
<internetadres>http://www.delijn.be/nieuws/.#oudejaarsnacht</internetadres>

<omschrijving>
<titel>Dienstregelingen en wedstrijd oudejaarsnacht beschikbaar vanaf 6 december</titel>
<datum>25 november 2004</datum>
<subtitel></subtitel>
<paragraaf id="1">Vanaf 6 december 2004 kunt u op deze website terecht voor de dienstregelingen en de wedstrijd voor oudejaarsnacht.</paragraaf>
</omschrijving>

</artikel>

<artikel id="2">
<titel>de nieuwslijn</titel>
<datum>26 november 2004</datum>
<inhoud>Tentoonstelling '100 jaar elektrische tram' nog tot 9 januari</inhoud>
<internetadres>http://www.delijn.be/oostvlaanderen/evenementen_elektrischetram.html</internetadres>
</artikel>

<artikel id="3">
<titel>de nieuwslijn</titel>
<datum>3 december 2004</datum>
<inhoud>4 december: betaalstaking in Oost-Vlaanderen</inhoud>
<internetadres>http://www.delijn.be/nieuws/#staking_ovl</internetadres>
</artikel>


</nieuwslijn>

 

This is the XSL(T) stylesheet:

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<div id="newscontainer"> 
   <h1><xsl:value-of select="nieuwslijn/artikel[@id='1']/titel"/></h1>
   <div id="news">
<p id="newsitem">
<a href="{nieuwslijn/artikel[@id='1']/internetadres}"><xsl:value-of select="nieuwslijn/artikel[@id='1']/inhoud"/></a>
</p>
<p id="endnewsitem">
<a href="{nieuwslijn/artikel[@id='2']/internetadres}"><xsl:value-of select="nieuwslijn/artikel[@id='2']/inhoud"/></a></p>
      </div>
    <div id="btimage"> </div>
 </div>

</xsl:template>
</xsl:stylesheet>

 

You can see that in the XSLT stylesheet, I have to specify each article number (artikel[id=x]) seperately. But I would like to write the code so that the page will 'walk through' these values.

 

These are the steps I want to add:

 

1. Walk through array "artikel[id=x]" until end of document is reached.

2. Last item:

a) Code of the last item has to differ slightly: <p id="endnewsitem"> instead of just <p>

B) + contain the extra code " </div> <div id="btimage"> </div> "

 

This is necessary to signal the end of the items in the list and draw the blue line underneath the last item.

 

3. Stop processing if end of document has been reached

 

A block of ASP code makes use of this XML and XSLT files to generate the corresponding block of code for the yellow news container at the top right of every page. E.g. see http://www.delijn.be/nieuws/

 

<%'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("/pathto/nieuwslijn.xml"))

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("/pathto/nieuwsoverzicht.xsl"))

'Transform file
Response.Write(xml.transformNode(xsl))
%>

 

 

Darkelve

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...