473,804 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I share code that selects a nodeset in XSLT?

I have an application where I have a shared "method" of selecting a nodeset.
The method currently is duplicated everywhere it is needed but I'd like that
code to be shared. The method also includes a conditional test (FWIW, the
test is whether a stylesheet parameter has a certain string value.)

<xsl:choose
<xsl:when test='$Generate ='Y'">
select node set one way
<xsl:otherwis e>
select node set another way

It's important to note that while the "method" of selection is common in
each occurence, I can't use a variable to store the nodeset once and reuse
for a number of reasons including the fact that there is no common scope
between the uses.
Is there a way to do this in XSLT V1? If there's a way to do it in V2, I'm
interested in hearing about it but I won't be able to use it.


Aug 24 '05 #1
4 1740
In XSLT 1.0 one either selects an expression into a global xsl:variable, or
passess it with an xsl:param to an applied/called template.

In XSLT 2.0 one will use xsl:function that returns a reference
(xsl:sequence) to the node-set.

Cheers,
Dimitre Novatchev.

"David Blickstein" <db@hp.com> wrote in message
news:43******** @usenet01.boi.h p.com...
I have an application where I have a shared "method" of selecting a
nodeset.
The method currently is duplicated everywhere it is needed but I'd like
that
code to be shared. The method also includes a conditional test (FWIW, the
test is whether a stylesheet parameter has a certain string value.)

<xsl:choose
<xsl:when test='$Generate ='Y'">
select node set one way
<xsl:otherwis e>
select node set another way

It's important to note that while the "method" of selection is common in
each occurence, I can't use a variable to store the nodeset once and reuse
for a number of reasons including the fact that there is no common scope
between the uses.
Is there a way to do this in XSLT V1? If there's a way to do it in V2,
I'm
interested in hearing about it but I won't be able to use it.

Aug 24 '05 #2

"Dimitre Novatchev" <di******@tpg.c om.au> wrote in message
news:43******** *************** @authen.white.r eadfreenews.net ...
In XSLT 1.0 one either selects an expression into a global xsl:variable, or passess it with an xsl:param to an applied/called template.
I don't think that works for my situation. Can you assign a global variable
in any context? I thought you could only assign it in the direct context of
the xsl:stylesheet element. And if so, that means it can only have one
value that applies everywhere. As I mentioned, the process is shared but
it is used in different contexts and uses different results.
In XSLT 2.0 one will use xsl:function that returns a reference
(xsl:sequence) to the node-set.
Oh well... nice to know they've solved this problem in the next version.
But I can't depend on my clients having 2.0... yet.

db

Cheers,
Dimitre Novatchev.

"David Blickstein" <db@hp.com> wrote in message
news:43******** @usenet01.boi.h p.com...
I have an application where I have a shared "method" of selecting a
nodeset.
The method currently is duplicated everywhere it is needed but I'd like
that
code to be shared. The method also includes a conditional test (FWIW, the test is whether a stylesheet parameter has a certain string value.)

<xsl:choose
<xsl:when test='$Generate ='Y'">
select node set one way
<xsl:otherwis e>
select node set another way

It's important to note that while the "method" of selection is common in
each occurence, I can't use a variable to store the nodeset once and reuse for a number of reasons including the fact that there is no common scope
between the uses.
Is there a way to do this in XSLT V1? If there's a way to do it in V2,
I'm
interested in hearing about it but I won't be able to use it.


Aug 24 '05 #3
XSLT is a functional programming language. It requires a different mindset
from the imperative programming one that crippled so many programmers.

Any problem, that can be solved with "assignment " can be solved in a
functional way.

In case you specify (the smallest possible) problem it is most likely that
many people will offer solutions.

Cheers,
Dimitre Novatchev.

"David Blickstein" <db@hp.com> wrote in message
news:43******** @usenet01.boi.h p.com...

"Dimitre Novatchev" <di******@tpg.c om.au> wrote in message
news:43******** *************** @authen.white.r eadfreenews.net ...
In XSLT 1.0 one either selects an expression into a global xsl:variable,

or
passess it with an xsl:param to an applied/called template.


I don't think that works for my situation. Can you assign a global
variable
in any context? I thought you could only assign it in the direct context
of
the xsl:stylesheet element. And if so, that means it can only have one
value that applies everywhere. As I mentioned, the process is shared but
it is used in different contexts and uses different results.
In XSLT 2.0 one will use xsl:function that returns a reference
(xsl:sequence) to the node-set.


Oh well... nice to know they've solved this problem in the next version.
But I can't depend on my clients having 2.0... yet.

db

Cheers,
Dimitre Novatchev.

"David Blickstein" <db@hp.com> wrote in message
news:43******** @usenet01.boi.h p.com...
>I have an application where I have a shared "method" of selecting a
>nodeset.
> The method currently is duplicated everywhere it is needed but I'd like
> that
> code to be shared. The method also includes a conditional test (FWIW, the > test is whether a stylesheet parameter has a certain string value.)
>
> <xsl:choose
> <xsl:when test='$Generate ='Y'">
> select node set one way
> <xsl:otherwis e>
> select node set another way
>
> It's important to note that while the "method" of selection is common
> in
> each occurence, I can't use a variable to store the nodeset once and reuse > for a number of reasons including the fact that there is no common
> scope
> between the uses.
>
>
> Is there a way to do this in XSLT V1? If there's a way to do it in
> V2,
> I'm
> interested in hearing about it but I won't be able to use it.
>
>
>
>



Aug 25 '05 #4
Is this what you're asking about? The description is sort of vague.

<xsl:param name="Generate" select="/doc/@Generate"/>
<xsl:param name="mynodeset ">
<nodes>
<hi/>
</nodes>
</xsl:param>

<xsl:template match="someElem ent">
<xsl:call-template name="selector"/>
</xsl:template>
<xsl:template name="selector" >
<xsl:choose
<xsl:when test='$Generate ='Y'">
<xsl:apply-templates
select="exsl:no de-set($mynodeset)/nodes/hi" mode="modeY"/>
</xsl:when>
<xsl:otherwis e>
<xsl:apply-templates mode="modeNotY"
select="exsl:no de-set($mynodeset)/nodes/hi" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="hi" mode="modeY">
Y said hi!
</xsl:template>
<xsl:template match="hi" mode="modeNotY" >
NotY said hi!
</xsl:template>

Aug 26 '05 #5

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

Similar topics

1
1803
by: Brian J. Sayatovic | last post by:
I'm using Xalan-J to loop through some nodes with an xsl:for-each element, presumably in document order. As far as I can tell, the XSL speciciation says that a for-each element will loop through the nodeset in document order, meaning the order the elements occur in the document. Does Xalan-J obey this rule? I'm encountering some oddities that could be explained if Xalan-J does not adhere to this, but it is a very rare circumstance, so...
4
3525
by: Brad | last post by:
Help, I have a really complicated XPATH request I can't wrap my head around I have an XML nodeset like this: <a> <a1 attr="key">Use</a1> <a1 attr="val">Value1</a2> </a> <a> <a1 attr="key">DontUse</a1>
1
2465
by: Damien Goutte-Gattat | last post by:
I am using the .NET framework v2.0.40607 with Visual C# Express and I would like to create some custom XPath functions to use directly in a XSLT stylesheet. I called System.Xml.Query.XmlArgumentList.AddExtensionObject(string, object) to register the functions I've written. The functions that take a String, Boolean or Number parameter work perfectly. However, I do not know how to create a function that will accept a Nodeset as a...
2
1840
by: amit L via DotNetMonster.com | last post by:
hi all. i've been trying to pass a nodelist (!=nodeset??) from my c# application to some xsl transform to use. the xsl code is as follows: <xsl:stylesheet version="1.0" exclude-result-prefixes="extern msxsl local xql" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:local="#local-functions" xmlns:xql="#xql-functions" xmlns:extern="urn:dottraffic:lnk">
1
1506
by: ssvendsen | last post by:
Hi, In my XML dialect I got elements on the form of XPath expressions, which refer to nodesets located in other fragments in the same document. Is there a way to validate that the XPath expression actually evaluates to what I expect (e.g. expected element names)? I can easily write a script which does the job, but would be happy to solve the problem with XSD, XSL or another 'standard' tool.
0
1251
by: Hoi-Polloi | last post by:
Hi all I want to use an xpath query to get a set of xmlNodePtr , but I don't want to keep the xmlXPathObject around. See the function below. I want to: * make xpath query and get an xmlXPathObjectPtr back * get a pointer (np) to the XPathObjectPtr->nodesetval->nodeTab * free XPathObjectPtr * return the pointer np ... but I'm not sure if np is still valid
2
1685
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of products like this one: <!-- File: Products.xml --> ... <Product id="p1">
14
1566
by: eric.goforth | last post by:
Hello, Is there any way to directly access an element in a nodeset? For example, if working with: <blahs rec_count="16"> <blah> <yada>abc</yada> </blah>
4
3331
by: vaibhavp | last post by:
Hi, I am new to coding in Xslt and am stuck up on a problem for a very long time. I have to convert an xml file to html using xslt. I am using javax.xml.transform API for this. The xml file i have contains data in the following format <person> <name>PERSON_NAME</name> <addressXML> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.