473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can you embed XML in XSL and access it?

I would like to embed some XML within my XSL as either a param or a
global variable. Is this possible? If so, what is the syntax to
access it?

<xsl:call-template name="securetemplate">
<xsl:with-param name="leftnav">
<links>
<link>Link 1</link>
<link>Link 2</link>
</links>
</xsl:with-param>
</xsl:call-template>

Thanks, John

Sep 29 '06 #1
9 1619

johkar wrote:
I would like to embed some XML within my XSL as either a param or a
global variable. Is this possible?

Yes. Stick it into your XSL as XML elements within a separate
namespace (and an easily findable root element). The use the XPath
document() function to access it.

Sep 29 '06 #2


johkar wrote:
I would like to embed some XML within my XSL as either a param or a
global variable. Is this possible? If so, what is the syntax to
access it?
You can embed XML data as a top level element (child of the
xsl:stylesheet element) if the element is in a different namespace e.g.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="http://example.com/2006/some-data"
version="1.0">

<data:data>
<links xmlns="">
<link>Link 1</link>
<link>Link 2</link>
</links>
</data:data>

The XSLT stylesheet itself can be accessed with calling the document
function with '' e.g.
document('')
so you would get at that data with e.g.
document('')/xsl:stylesheet/data:data/links/link
to access all the link elements.
If you use xsl:param or xsl:variable and have contents in these elements
then you have a result tree fragment as the parameter or variable value
that you can later copy to the result tree with xsl:copy-of e.g.

<xsl:call-template name="securetemplate">
<xsl:with-param name="leftnav">
<links>
<link>Link 1</link>
<link>Link 2</link>
</links>
</xsl:with-param>
</xsl:call-template>

<xsl:template name="securetemplate">
<xsl:param name="leftnav"/>
<xsl:copy-of select="$leftnav"/>
</xsl:template>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 29 '06 #3

johkar wrote:
I would like to embed some XML within my XSL as either a param or a
global variable. Is this possible? If so, what is the syntax to
access it?
Excellent. Thank you both. That was record response time to boot.

John

Sep 29 '06 #4

Martin Honnen wrote:
johkar wrote:
I would like to embed some XML within my XSL as either a param or a
global variable. Is this possible? If so, what is the syntax to
access it?

You can embed XML data as a top level element (child of the
xsl:stylesheet element) if the element is in a different namespace e.g.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="http://example.com/2006/some-data"
version="1.0">

<data:data>
<links xmlns="">
<link>Link 1</link>
<link>Link 2</link>
</links>
</data:data>

The XSLT stylesheet itself can be accessed with calling the document
function with '' e.g.
document('')
so you would get at that data with e.g.
document('')/xsl:stylesheet/data:data/links/link
to access all the link elements.
If you use xsl:param or xsl:variable and have contents in these elements
then you have a result tree fragment as the parameter or variable value
that you can later copy to the result tree with xsl:copy-of e.g.

<xsl:call-template name="securetemplate">
<xsl:with-param name="leftnav">
<links>
<link>Link 1</link>
<link>Link 2</link>
</links>
</xsl:with-param>
</xsl:call-template>

<xsl:template name="securetemplate">
<xsl:param name="leftnav"/>
<xsl:copy-of select="$leftnav"/>
</xsl:template>
One more question. If data:data is on the main page, how can you
access it in an included xsl?

John

Oct 1 '06 #5
johkar wrote:
One more question. If data:data is on the main page, how can you
access it in an included xsl?
I'm not sure what you mean by "main page" in this context. The main
stylesheet? If you know the URI for that stylesheet, you can ask the
document function to retrieve from that specific URI. If you don't know
the URI, you may have to pass it down as a parameter ... or just pass a
reference to that data:data element down as a parameter.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Oct 1 '06 #6
Joe Kesselman wrote:
johkar wrote:
One more question. If data:data is on the main page, how can you
access it in an included xsl?

I'm not sure what you mean by "main page" in this context. The main
stylesheet? If you know the URI for that stylesheet, you can ask the
document function to retrieve from that specific URI. If you don't know
the URI, you may have to pass it down as a parameter ... or just pass a
reference to that data:data element down as a parameter.
I have only been able to get one scenario to work, if I have the
data:data namespace and the document function on the same stylesheet.
If I want to output various nodes from the data:data XML from and
included stylesheet, I cannot get it to work. I have tried passing
references and other things suggested, but my syntax is apparently
incorrect. We use Xalan if that makes a difference. Below is an
example.

Thanks, John

Main template
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="http://example.com/2006/some-data">
<xsl:include href="common/leftcol.xsl" />

<data:data>
<links xmlns="">
<link name="selected">Link 1</link>
<link>Link 2</link>
</links>
</data:data>

<xsl:template match="/">
<xsl:call-template name="leftcol" />
</xsl:template>
</xsl:stylesheet>

Left Column Template

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="http://example.com/2006/some-data">
<xsl:template name="leftcol">
<xsl:value-of
select="document(common/mainPage.xsl)/data:data/links/link[@name='selected']"
/>
</xsl:template>
</xsl:stylesheet>

Oct 2 '06 #7


johkar wrote:

<xsl:value-of
select="document(common/mainPage.xsl)/data:data/links/link[@name='selected']"
/>
I think you want/need
document('common/mainPage.xsl')/xsl:stylesheet/data:data/links/link[@name='selected']
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 2 '06 #8
Martin Honnen wrote:
I think you want/need
document('common/mainPage.xsl')/xsl:stylesheet/data:data/links/link[@name='selected']
Sorry, this is my directory structure:

common/leftcol.xsl
main/mainPage.xsl (this is the main stylesheet)

I tried both of these in leftcol.xsl, but nothing has worked so far:

document('main/mainPage.xsl')/xsl:stylesheet/data:data/links/link[@name='selected']

and

document('../main/mainPage.xsl')/xsl:stylesheet/data:data/links/link[@name='selected']

Oct 2 '06 #9

Martin Honnen wrote:
johkar wrote:

<xsl:value-of
select="document(common/mainPage.xsl)/data:data/links/link[@name='selected']"
/>

I think you want/need
document('common/mainPage.xsl')/xsl:stylesheet/data:data/links/link[@name='selected']
Ok, I don't know what happened, but since I couldn't get the path
correct, I tried passing a reference to the document() and it worked
this time...go figure.

So within my call-template, I included a reference. I know I tried
this before.
<xsl:with-param name="leftcol" select="document('')" />

Thanks everyone.

Oct 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Kenickney | last post by:
Suppose I have an MS access database with query1 and query2. Query2 uses query1 something like this: Select table.* from (table left join query1 on field1=field2) Now I want to make a change...
2
by: Phil | last post by:
Hi, I want to access the features of a plugin without actually embedding it into a page. Is this possible? Eg The code to embed the object into a page is: <OBJECT...
2
by: Eric Barr | last post by:
I've found myself using XSD files for my datasets. I'm loading them up from disk right now. I was hoping there was a way to embed the file in the assembly, so I could have access to it without...
1
by: Ed Landau | last post by:
Is there a way to embed a picture in a table? I want to store MP3 cover art in a table along with artist info etc. Is that what an "OLE Object" is? I'm trying to populate the table with VB...
0
by: beau | last post by:
Re. Embed or save ms word into OLE field Please help me ! Anybody can help me with a code to embed an ms word file into an access table ? I have ms word templates with bookmarks in my hard...
3
by: anthonytjea | last post by:
Hi all, Iam trying to embed the well known Month Calendar found at http://www.lebans.com/monthcalendar.htm directly into an MS Access form the same way that the ActiveX Calendar Control is...
3
by: M | last post by:
Hi Folks, Does anyone know how to embed a file into a resource in C#? You seem to be able to embed Icon, Bitmap, Cursor's & Strings. But how do you embed a file??? In VC++ version 6 you...
8
by: CodeLeon | last post by:
Hi, All. I am creating a setup program. The way it works is that the user creates their setup info, my program generates the C# code for a setup executable, embeds the xml file containing the info...
0
by: VigneshS | last post by:
Hi, I am a newbie to Globalization and Localisation Concepts. I tried almost all the methods of the Globalization concepts. But i cannot be able to embed a text file within a Resource. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.