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

RE: variable holding a xml document created by xslt

Subject: RE: variable holding a xml document created by xslt
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Sun, 11 Apr 2004 02:19:15 -0600
xslt variable document
The answer is...  yes... and no...  Confused?  Well, heres the deal...
In XSLT 1.0 there is no official way to create a variable that contains
a node-set which is what you need to accomplish what you want(it either
a Result Tree Fragment or a string, depending on how its created).  This
was one thing that was left out that all agree should have been there.
As such pretty much every XSLT vendor has implemented some sort of way
to serialize a Result Tree Fragment or a string (which is what you would
be creating in this case) into a node-set.  Xalan uses xalan:nodeset(),
msxsl uses msxsl:node-set(), Saxon uses the EXSLT extension, and so
on... you will need to look at the docs for the processor you are using
to find out how they implement this function.  Remember, in all cases
you are going to need to declare the proper namespace in your stylesheet
element.  The docs will tell you the proper format.

But, before you get to far into that process there is a way to create a
"look-up" table within the scope of your stylesheet that you can then
reference using the document() function that is part of the 1.0 spec and
therefore supported without any extensions in all 1.0 compliant
processors.  So, for example, the following XSLT...

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:lookup="uri:lookup"
                exclude-result-prefixes="lookup"
                version="1.0">
                
<lookup:labels>
 <label x1="100" y1="110" x2="120" y2="115"/>
 <label x1="..." y1="..." x2="..." y2="..."/>
 <label x1="..." y1="..." x2="..." y2="..."/>
</lookup:labels>

<xsl:variable name="labels" select="document('')/*/lookup:*"/>
    
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
  <xsl:apply-templates select="$labels/*"/>
</xsl:template>

<xsl:template match="label">
  <xsl:element name="label">
    <xsl:apply-templates select="@*" mode="attributes"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@*" mode="attributes">
  <xsl:element name="{name()}">
    <xsl:value-of select="."/>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>

Would give you this output:

<?xml version="1.0" encoding="UTF-8"?>
<label>
  <x1>100</x1>
  <y1>110</y1>
  <x2>120</x2>
  <y2>115</y2>
</label>
<label>
  <x1>...</x1>
  <y1>...</y1>
  <x2>...</x2>
  <y2>...</y2>
</label>
<label>
  <x1>...</x1>
  <y1>...</y1>
  <x2>...</x2>
  <y2>...</y2>
</label>

You obviously need to modify this to fit what you are looking for but
this should help get you going in the right direction... let me know if
you need any more help..

Best regards,

<M:D/>



-----Original Message-----
From: Robert Van Gemert [mailto:rcvangemert@xxxxxxxxxxxxxxxx] 
Sent: Sunday, April 11, 2004 1:54 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  variable holding a xml document created by xslt

Hi,

Battling with a stylesheet to display svg maps and making good
progress!,
one of my last problems is placing lables so they don't overlap.

Using xslt can I create a variable that holds xml, for example I want to
create a variable that holds the dimentions of  many lables eg.

<labels>
 <label x1="100" y1="110" x2="120" y2="115"/>
 <label x1="..." y1="..." x2="..." y2="..."/>
 <label x1="..." y1="..." x2="..." y2="..."/>
</labels>


My idea is to call a template and return a list of lables.

With xslt I can return a single variable or a node from the input
document
but I cannot get my mind around returning a xml tree that I construct
using
code (in one pass).

Thanks,

Robert

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.