[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: my.office@xxxxxx
Date: Sun, 20 Nov 2005 14:39:55 +0100 (MET)
div in loop
Hi Ken,

thank you for your example, but there are some problems according to the
following examples.

I've changed (a little bit) your code that "nearly" no html-tag is used
in the xslt-file.

[...]

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

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>

test.html (or .xml):
*************
<!-- news template -->
<table>
	<tr loop="row"><td myid="title">dummytitel</td><td
myid="num">1234</td><td></td></tr>
</table>
<!-- /news template -->

test.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 method="html" omit-xml-declaration="yes" indent="yes"/>

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

<!--found an attribute "loop"-->
<xsl:template match="*[@loop]">
	<!--remember the cells of the row for later-->
	<xsl:variable name="loop" select="*" />
<!-- remember tagname of the loop-element to generate element later-->
<xsl:variable name="looptag" select="name()" />
	<xsl:for-each select="$datafile/data/*[local-name(.)=current()/@loop]">
		<!--building a row based on the specified row-oriented element-->
		<xsl:element name="{$looptag}">
		<!--need to remember the row context when doing the cells-->
		<xsl:variable name="row" select="." />
		<xsl:for-each select="$loop">
<!-- FIXME: show element-tag from source (html-file) -->
			<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>
		</xsl:element>
	</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>

**************************************
result:
*************
<!-- news template -->
<table>
  <tr>
    <td>Title A</td><td>123</td><td></td>
  </tr>
  <tr>
    <td>Title B</td><td>456</td><td></td>
  </tr>
  <tr>
    <td>Title C</td><td>789</td><td></td>
  </tr>
</table>
<!-- /news template -->

^ which is ok for this html-template

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

So, considering the html-template-file the xsl-file shouldn't contain _any_
html-tag to
produce the resulting html/xml-file rather get the tag from the source-file.

ex. A:

test.html (or .xml):
***********************
<!-- news template -->
<table>
<tr loop="row">
	<td><div><div myid="title">dummycontent</div></div></td>
	<td myid="num">1234</td>
	<td>Blah</td>
</tr>
</table>
<!-- /news template -->

which should result in:
***********************
<!-- news template -->
<table>
<tr>
	<td><div><div>Title A</div></div></td>
	<td myid="num">123</td>
	<td>Blah</td>
</tr>
<tr>
	<td><div><div>Title B</div></div></td>
	<td myid="num">456</td>
	<td>Blah</td>
</tr>
<tr>
	<td><div><div>Title C</div></div></td>
	<td myid="num">789</td>
	<td>Blah</td>
</tr>
</table>
<!-- /news template -->

or

ex. B:

test.html (or .xml):
***********************
<!-- news template -->
<div loop="row">
	<div myid="title">dummycontent&nbsp;<div
myid="num">dummyconten2</div></div>
</div>
<!-- /news template -->

which should result in:
***********************
<!-- news template -->
<div>
	<div>Title A<div>123</div></div>
</div>
<div>
	<div>Title B<div>456</div></div>
</div>
<div>
	<div>Title C<div>789</div></div>
</div>
<!-- /news template -->

or a more complex example with recursion:

test.html (or .xml):
***********************
<!-- news template -->
<div loop="row">
	<div myid="title">dummycontent</div>
	<div myid="num">dummyconten2</div>
	<div loop="nested">
		<div myid="title">dummy2</div>
		<div loop="third">
			<div myid="name"></div>
		</div>
	</div>
</div>
<!-- /news template -->

with xml-data:
***********************
<data>
	<row class="col0">
		<title>Title A</title>
		<num>123</num>
		<nested>
			<title>NestedTitle</title>
			<third>
				<name>MyName</name>
				<name>MyName2</name>
			</third>
		</nested>
	</row>
	<row class="col1">
		<title>Title B</title>
		<num>456</num>
		<nested>
			<title>NestedTitle2</title>
			<third></third>
		</nested>
		<nested>
			<title>NestedTitle3</title>
			<third>
				<name>MyName3</name>
			</third>
		</nested>
	</row>
</data>



which should result in:
<!-- news template -->
<div>
	<div>Title A</div>
	<div>123</div>
	<div>
		<div>NestedTitle</div>
		<div>
			<div>MyName</div>
			<div>MyName2</div>
		</div>
	</div>
</div>
<div>
	<div>Title B</div>
	<div>456</div>
	<div>
		<div>NestedTitle2</div>
		<div></div>
	</div>
	<div>
		<div>NestedTitle3</div>
		<div>
			<div>MyName3</div>
		</div>
	</div>
</div>
<!-- /news template -->


******

Is this possible with one xslt-file?

Thank you for any comment/example in advance.

Milli Jolie


-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen f|r GMX Partner: http://www.gmx.net/de/go/partner

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.