XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Edwin HeijmenSubject: How to transform node from included document
Author: Edwin Heijmen
Date: 04 Jul 2008 08:23 AM
Is the following possible? I can't seem to wrap my head around it, but I am an XSLT newbie, so that might explain it :)

I have an XML file that contains data that needs to be displayed:
<?xml version="1.0" ?>
<top>
<data>
<title>title of page</title>
<name>Your name</name>
</data>
<cells>
<cell>
<name>cell 1</name>
<value>100</value>
</cell>
<cell>
<name>cell 2</name>
<value>200</value>
</cell>
<cell>
<name>cell 3</name>
<value>300</value>
</cell>
</cells>
</top>

I also have a layout XML file that will be used to put the data from the above XML-file into a certain layout, called layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout>
<layout-main>
<html>
<head>
<title><insert-title/></title>
</head>
<body>
<div>
My name is: <insert-name/>
</div>
<div>
<table>
<insert-cells/>
</table>
</div>
</body>
</html>
</layout-main>
<layout-cell>
<tr>
<td><insert-cell-name/></td>
<td><insert-cell-value/></td>
</tr>
</layout-cell>
</layout>

And then I have the XSL file to tie it all together (hopefully!):
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:variable name="data" select="/"/>
<xsl:variable name="layout" select="document('layout.xml')"/>
<xsl:template match="/">
<xsl:apply-templates select="$layout/layout/layout-main/*"/>
</xsl:template>
<!-- transformations -->
<xsl:template match="insert-name">
<xsl:value-of select="$data/top/data/name"/>
</xsl:template>
<xsl:template match="insert-title">
<xsl:value-of select="$data/top/data/title"/>
</xsl:template>
<xsl:template match="insert-cells">
<xsl:for-each select="$data/top/cells/cell">
<xsl:variable name="name" select="name"/>
<xsl:variable name="value" select="value"/>
<xsl:value-of select="name"/>
<xsl:apply-templates select="$layout/layout/layout-cell/tr">
<xsl:with-param name="name" select="$name"/>
</xsl:apply-templates>
<xsl:call-template name="insert-cell-name">
<xsl:with-param name="name" select="$name"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="insert-cell-name">
<xsl:param name="name" select="name"/>
<xsl:value-of select="name"/>
</xsl:template>
<!-- Identity transformation -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I would like the output to look like the following"
<html>
<head>
<title>title of page</title>
</head>
<body>
<div>
My name is: Your name
</div>
<div>
<table>
<tr>
<td>cell 1</td>
<td>100</td>
</tr>
<tr>
<td>cell 2</td>
<td>200</td>
</tr>
<tr>
<td>cell 3</td>
<td>300</td>
</tr>
</table>
</div>
</body>
</html>

Unfortunately that's not quite the result. I can't seem to be able to replace the 'insert-cell-name' and 'insert-cell-value' tags with the corresponding 'name' and 'value' tag values. Is this possible?

The reason I want to keep as much layout out of the XLS-file as possible is to allow non-developers to design a layout without knowing XSLT. This way I can hopefully also use a single XLS-file where 'layout.xml' can be easily changed/generated.

Thanxxx for any guidance/advice/comments...

Posttop
(Deleted User) Subject: How to transform node from included document
Author: (Deleted User)
Date: 08 Jul 2008 06:25 AM
Hi Edwin,
which version of Stylus Studio are you using? And which XSLT engine have you selected in the scenario of your XSLT stylesheet?

Thanks,
Alberto

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.