XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 31st, 2004, 04:05 PM
krisbeyers krisbeyers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 6 krisbeyers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Problem sending merged xml data from one xsl file to another

Hoi,

I have a little problem in sending the merged XML data to the file adds.xsl.
The idea is to have different adds on different websites, but combining them together
for each website with the help of a source list.

When I add <?xml-stylesheet type="text/xsl" href="merge.xsl"?> in the file sources.xml and open this file,
I can tell that the data is merged correctly, but if I open adds.xml, only the html table appears
without the data that should have been merged.

the newline to <br /> translater works also fine.

Any help would be appreciated :)

Greets,
Kris


file sources.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<files>
<file>adds1.xml</file>
<file>adds2.xml</file>
</files>

file adds1.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<adds>
<add>
<nickname>Ellen</nickname>
<country>Belgium</country>
<city>Antwerp</city>
<birthday>06-04-1982</birthday>
<email>ellen@nomail.be</email>
<introduction>hoi, ik zoek een leuke jongen</introduction>
<looksfor>description goes here</looksfor>
<gender>V</gender>
<url>www.ellen.be</url>
</add>
</adds>

file adds2.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<adds>
<add>
<nickname>Kris</nickname>
<country>Belgium</country>
<city>Kapellen</city>
<birthday>25-04-1979</birthday>
<email>kris@nomail.com</email>
<introduction>this is my personal discription</introduction>
<looksfor>i am looking for someone nice</looksfor>
<gender>m</gender>
<url>users.pandora.be/ellen</url>
</add>
</adds>

file merge.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>

<xsl:template match="/">
<adds_merged>
<xsl:for-each select="document('sources.xml')/files/file">
<xsl:variable name="file" select="document(text())"/>
<xsl:copy-of select="$file/adds/child::*"/>
</xsl:for-each>
</adds_merged>
</xsl:template>

<xsl:variable name="x" select="document('')" />

</xsl:stylesheet>

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

<xsl:include href ="merge.xsl" />

<xsl:template match="/">
<html>
<body bgcolor="white">
<h2>Mijn zoekertjes</h2>
<table border="1">
<tr>
<th>Nicknaam</th>
<th>E-mail</th>
<th>Voorstelling</th>
<th>Geboortedatum</th>
<th>M/V</th>
<th>Geaardheid</th>
<th>Url</th>
</tr>
<xsl:for-each select="$x/adds_merged/add">
<tr>
<td>
<xsl:value-of select="nicknaam"/>
</td>
<td>
<a target="_top">
<xsl:attribute name="HREF">mailto:<xsl:value-of select="email"/></xsl:attribute>
<xsl:value-of select="email"/>
<foo xml:space="preserve"> </foo>
</a>
</td>
<td>
<xsl:variable name="StringIn">
<xsl:value-of select="introduction"/>
</xsl:variable>
<xsl:variable name="ResultTreeFragmentOut">
<xsl:call-template name="nl2br">
<xsl:with-param name="StringToTransform" select="$StringIn" />
</xsl:call-template>
</xsl:variable>
<xsl:copy-of select="$ResultTreeFragmentOut" />
</td>
<td>
<xsl:value-of select="birthday"/>
</td>
<td>
<xsl:value-of select="gender"/>
</td>
<td>
<xsl:value-of select="sexualinclination"/>
</td>
<td>
<a target="_top">
<xsl:attribute name="HREF">http://<xsl:value-of select="url"/></xsl:attribute>
<xsl:value-of select="url"/>
<foo xml:space="preserve"> </foo>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

<!-- template that "translates newlines to <br/> tags" -->
<xsl:template name="nl2br">
<xsl:param name="StringToTransform"/>
<xsl:choose>
<!-- string contains newline -->
<xsl:when test="contains($StringToTransform,'
')">
<xsl:value-of select="substring-before($StringToTransform,'
')"/>
<br/>
<xsl:call-template name="nl2br">
<xsl:with-param name="StringToTransform">
<xsl:value-of select="substring-after($StringToTransform,'
')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$StringToTransform"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

adds.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="adds.xsl"?>
<foo></foo>

Reply With Quote
  #2  
Old June 2nd, 2004, 06:56 PM
krisbeyers krisbeyers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 6 krisbeyers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
problem solved

Hoi,

Found a very good solution to merge different xml files for my problem.
just use the following: <xsl:for-each select="document(files/file[/])/adds/add">
the file adds.xml and adds.xsl dissapeared, and everything went into the file sources.xsl

this works even in IE5

Greetings,
Kris

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Problem sending merged xml data from one xsl file to another


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway