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

Re: Is it possible to access a tag after using apply-

Subject: Re: Is it possible to access a tag after using apply-templates?
From: XemonerdX <xemonerdx@xxxxxxxxx>
Date: Fri, 4 Jul 2008 17:01:04 +0200
Re:  Is it possible to access a tag after using  apply-
Michael,

That sounds very interesting and something I will have to try. My main
concern at this point is that there will be dozens of xsl:param's and
xsl:template's that would have to be generated into an XSLT stylesheet
(this will be for applications that need to display a lot of data,
each record can hold many (dynamic) fields etc). Generating such an
XSLT is not a problem now that I have the basic structure thanks to
Martin's example. However, I am wondering if the performance will
deterriorate a lot becuz of the amount of xsl:param's passed around?

Would your double-pass approach help in such a case? Considering data
is gradually compiled into larger bits, I would imagine it's better
performance-wise, but not sure.

Thank you,

Edwin

On Fri, Jul 4, 2008 at 4:40 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> Another way of tackling this kind of problem, which I've generally found
> works better in the long run, is as follows. At present you essentially have
> a miniature layout language, and you have written an interpreter in XSLT
> that interprets that language, fetching data from a source document when the
> layout script instructs you to do so.
>
> The alternative approach is to compile your layout language: that is, to
> write an XSLT stylesheet that converts it into an XSLT stylesheet, which
> then operates on the data file directly.
>
> Michael Kay
> http://www.saxonica.com/
>
>> -----Original Message-----
>> From: XemonerdX [mailto:xemonerdx@xxxxxxxxx]
>> Sent: 04 July 2008 14:56
>> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> Subject:  Is it possible to access a tag after using
>> apply-templates?
>>
>> 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('http://localhost/webopac2/xml/datatemplate_l
>> ayout.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: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"/>
>>       <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...
>>
>> Edwin
>
>



-- 
Edwin
PoeticTerror.Com

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.