[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: html + xml -> xsl -> html - Problem

Subject: Re: html + xml -> xsl -> html - Problem
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 19 Nov 2005 18:17:20 -0500
html in xml xsl
At 2005-11-19 23:32 +0100, my.office@xxxxxx wrote:
i've got a problem with 2 files resulting in 1 trough xsl.

You don't say where you are having the problem ... how far did you get?


I want to parse a html-template that should be filled with data
from a xml-file.

Fine ...


The thing is that i don't want to put the html-stuff inside the xsl-file
because the template could be changed.

Fine ...


The result should be:

<!-- news template -->
<table>
<tr><td>Titel A</td><td>123</td></tr>
<tr><td>Titel B</td><td>456</td></tr>
<tr><td>Titel C</td><td>789</td></tr>
</table>
<!-- /news template -->

Could someone give me an example how to get this?

I hope the example below helps, but I'm not sure where you were having the problem to start with so I don't know what to bring to your attention.


. . . . . . . . Ken

T:\ftemp>type data.xml
<data>
        <row class="col0">
                <title>Title A</title>
                <num>123</num>
        </row>
        <row class="col1">
                <title>Title B</title>
                <num>456</num>
        </row>
        <row class="col2">
                <title>Title C</title>
                <num>789</num>
        </row>
</data>

T:\ftemp>type jolie.xml
<table>
<tr loop="row"><td myid="title">dummytitel</td><td myid="num">1234</td></tr>
</table>

T:\ftemp>type jolie.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output indent="yes"/>

<!--the external data to be added to the HTML source when building output-->
<xsl:variable name="datafile" select="document('data.xml')"/>

<!--found a table row that loops on the data file-->
<xsl:template match="tr[@loop]">
  <!--remember the cells of the row for later-->
  <xsl:variable name="cells" select="td"/>
  <xsl:for-each select="$datafile/data/*[local-name(.)=current()/@loop]">
    <!--building a row based on the specified row-oriented element-->
    <tr>
      <!--need to remember the row context when doing the cells-->
      <xsl:variable name="row" select="."/>
      <xsl:for-each select="$cells">
        <td>
          <!--match the cell's element name as asked for in attribute-->
          <xsl:value-of select="$row/*[local-name(.)=current()/@myid]"/>
        </td>
      </xsl:for-each>
    </tr>
  </xsl:for-each>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>xslt jolie.xml jolie.xsl con
<?xml version="1.0" encoding="utf-8"?>
<table>

   <tr>
      <td>Title A</td>
      <td>123</td>
   </tr>
   <tr>
      <td>Title B</td>
      <td>456</td>
   </tr>
   <tr>
      <td>Title C</td>
      <td>789</td>
   </tr>

</table>
T:\ftemp>


-- Upcoming XSLT/XSL-FO hands-on courses: Denver,CO March 13-17,2006 World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.