473,762 Members | 8,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT and document()/Node

Hello,

I've got a problem. Either I have missed the most important point or
it really does not work:

I want to use the document function with an absolut path on WindowsXP
Professional and Saxon 8.1. However, retrieving a subnode of the
documents content is not possible. Inserting a whole document result
set is functional, subset not. Example:

001 <?xml version="1.0"?>
002 <xsl:styleshe et version="1.1"
003 xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
004 <xsl:param name="files" select="''"/>
005 <xsl:template match="/">
006 <Service>
007 <xsl:call-template name="concatena teFiles">
008 <xsl:with-param name="theFiles"
009 select="concat( normalize-space($files), ' ')"/>
010 </xsl:call-template>
011 </Service>
012 </xsl:template>
013
014 <xsl:template name="concatena teFiles">
015 <xsl:param name="theFiles"/>
016 <xsl:variable name="file"
017 select="substri ng-before($theFile s, ' ')"/>
018 <xsl:copy-of select="documen t($file)/Service/Output"/>
019 <xsl:variable name="rest"
020 select="substri ng-after($theFiles , ' ')"/>
021 <xsl:if test="$rest">
022 <xsl:call-template name="concatena teFiles">
023 <xsl:with-param name="theFiles" select="$rest"/>
024 </xsl:call-template>
025 </xsl:if>
026 </xsl:template>
027 </xsl:stylesheet>

Passing an existing file to the "files" parameter does not work at
all. A simple <Service/> is returned. Reducing line 021 to

018 <xsl:copy-of select="documen t($file)"/>

does work, however doesn't achive the desired result to incorporate
just a subnode of the document loaded.

I am thankful for any hints in this concern.

Daniel Frey
Jul 20 '05 #1
8 3663

018 <xsl:copy-of select="documen t($file)/Service/Output"/> 018 <xsl:copy-of select="documen t($file)"/>
does work,


presumably your documents don't have top level element Service with
children Output (perhaps they have elements in some namespace?)

Incidentally since you are using saxon 8 and so xslt2 you needn't step
through that space separated list of filenames using recursion on
substring; you can coerce it directly to a sequence of strings and then
iterate over the sequence.

David
Jul 20 '05 #2
Thanks for your reply. The xml in question has got a <Service> element.
And your right, there is a namespace in the element.

The abstracted xml source look like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Service xmlns="uri://bw.ubs.com/map">
<Header ...>
<Status ...>
<Output ...>
</Service>

How do I address the nodes in a namespace attributed element?

I do not understand the other hint you gave me completely. Can you give
a small sample of "coercing" the string list directly?

Thank you for your help.

Daniel Frey

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

an Xpath of /Service/... matches the element with empty namespace URI
and local name Service, you want to match an element with namespace URI
uri://bw.ubs.com/map and local name Service (incidentally I don't think
there is a registered uri scheme of uri: is there? Not that The
Namespace spec cares if the namespace URI is valid as a URI.

In XSLT1 (and this also works in 2) you need to use prefixed expressions
in the xpath, stick
xmlns:x="uri://bw.ubs.com/map"
on your xsl:stylesheet and then use
/x:Service/x:Output

(You don't need to change your source documents)

Since you are using the XSLT2 draft you could instead change the default
Xpath element name namespace by putting
xpath-default-namespace="uri://bw.ubs.com/map"
on your xsl:stylesheet element, but that will affect _all_ Xpath's in
the stylesheet so if some of your input is not in that namespace this
might not be what you want.
I do not understand the other hint you gave me completely. Can you give
a small sample of "coercing" the string list directly?


You could use the as attribute on the xsl:param to force it to be
interpretted as a sequence of strings, or more explictly, gven the white
space separated string you could do

<xsl:for-each select="tokeniz e($files,'\s+') ">
<xsl:copy-of select="doc(.)/....

see
http://www.w3.org/TR/xquery-operators/#func-tokenize
David
Jul 20 '05 #4
Thank you very much David. I copied the namespace solution, perfect! The
tokenize solution is also easy to understand. It simplifies the
stylesheet enormously!

However, I get an exception in saxon 8.1 driver when running the code.
The stylesheet looks now like this:

001 <?xml version="1.0"?>
002 <xsl:styleshe et version="1.1"
003 xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
004 xmlns:u="uri://bw.ubs.com/map">
005 <xsl:output indent="yes"/>
006 <xsl:param name="files" select="''"/>
007 <xsl:template match="/">
008 <Service>
009 <xsl:for-each select="tokeniz e($files,'\s+') ">
010 <xsl:copy-of select="documen t(.)/u:Service"/>
011 </xsl:for-each>
012 </Service>
013 </xsl:template>
014 </xsl:stylesheet>

But line 009 throws a ClassCastExcept ion.

java.lang.Runti meException: net.sf.saxon.va lue.StringValue
java.lang.Class CastException: net.sf.saxon.va lue.StringValue
at
com.exln.stylus .CSaxon8Driver. startCurrentIte m(CSaxon8Driver .java:1100)
at net.sf.saxon.in struct.ForEach. processLeavingT ail(ForEach.jav a:125)
at net.sf.saxon.in struct.Instruct ion.process(Ins truction.java:9 1)
at
net.sf.saxon.in struct.TraceWra pper.processLea vingTail(TraceW rapper.java:
79)
at net.sf.saxon.in struct.Instruct ion.process(Ins truction.java:9 1)
at
net.sf.saxon.in struct.Instruct ionWithChildren .processChildre n(Instructio
nWithChildren.j ava:158)
at
net.sf.saxon.in struct.ElementC reator.processL eavingTail(Elem entCreator.j
ava:122)
at net.sf.saxon.in struct.Instruct ion.process(Ins truction.java:9 1)
at
net.sf.saxon.in struct.TraceWra pper.processLea vingTail(TraceW rapper.java:
79)
at
net.sf.saxon.in struct.Instruct ionWithChildren .processChildre nLeavingTail
(InstructionWit hChildren.java: 196)
at net.sf.saxon.in struct.Block.pr ocessLeavingTai l(Block.java:11 7)
at net.sf.saxon.in struct.Instruct ion.process(Ins truction.java:9 1)
at
net.sf.saxon.in struct.TraceWra pper.processLea vingTail(TraceW rapper.java:
79)
at net.sf.saxon.in struct.Template .expand(Templat e.java:98)
at net.sf.saxon.in struct.Template .processLeaving Tail(Template.j ava:82)
at
net.sf.saxon.in struct.ApplyTem plates.applyTem plates(ApplyTem plates.java:
226)
at net.sf.saxon.Co ntroller.transf ormDocument(Con troller.java:10 94)
at net.sf.saxon.Co ntroller.transf orm(Controller. java:940)
at com.exln.stylus .CSaxon8Driver. doProcessing(CS axon8Driver.jav a:169)
at com.exln.stylus .CProcessorDriv er.process(CPro cessorDriver.ja va:55)
The parameter passed (without line breaks) is

C:/DOKUME~1/DANIEL~1/LOKALE~1/Temp/test42553/workflow/work42555.2
C:/DOKUME~1/DANIEL~1/LOKALE~1/Temp/test42553/workflow/work42555.4
C:/DOKUME~1/DANIEL~1/LOKALE~1/Temp/test42553/workflow/work42555.6

But I still have the fallback solution I used before. Anyway, a big
thank you for your help!

Daniel Frey

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

If you get a java exception raised by saxon (or any xslt engine) 'tis a
bug in the processor. If you pass that on to Michael at saxon's help
email address I'm sure he'll look at it.

I'm surprised that saxon's document() function accepts
C:/DOKUME~1/DANIEL~1/LOKALE~1/Temp/test42553/workflow/work42555.2
(however you split that off your string) as it is supposed to be a URI
and C: isn't known uri scheme (which needs to be file: or http: or ftp:
or some such) that should be
file:///C:/DOKUME~1/DANIEL~1/LOKALE~1/Temp/test42553/workflow/work42555.2
however I doubt that is the cause of your exception.

David
Jul 20 '05 #6
> <xsl:copy-of select="documen t($file)"/>

does work, however doesn't achive the desired result to incorporate
just a subnode of the document loaded.


Hi,

try: 'document($file )//Service' in stead of 'document($file )/Service'. In practical situations, I've epercienced that '/' fails to work when handling a document node. I'm not sure why, though.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #7
"Joris Gillis" <ro**@pandora.b e> writes:
try: 'document($file )//Service' in stead of
'document($file )/Service'. In practical situations, I've epercienced
that '/' fails to work when handling a document node. I'm not sure
why, though.

regards,


If you know that Service is the top level element then // is an
expensive thing to try since it tells the system to search the entire
document to arbitrary depth looking for all Service' elements.

If Service' is not the top level element then clearly /Service won't
work but its usually better to use a more explict path than // so as to
limit searching, eg /*/Service if it's a second level element.

David
Jul 20 '05 #8
In my case it is not suitable to use //Service as the Output element
contains another Service element which should not be incorporated. And I
have the impression that this would not solve the namespace issue, would
it? In my case I would use something like //u:Service to address all
Service elements, wouldn't I?

Daniel

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #9

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

Similar topics

0
2712
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the same XML file with XSL file with a program called XMLspy and i obtained the desire and waited...
1
8686
by: Victor | last post by:
Hi, this might sound silly but I cannot figure out how to incorporate some XML of employees into some XML of a company to give new XML containing them all. For example, this is the company now <COMPANY> <EMPLOYEE currentEmployee="true"> <NAME>Victor</NAME>
3
2142
by: Justine Hlista | last post by:
I'm using xalan-j_2_6_0 and trying to get an example from Michael Kay's book to work: <xsl:template match="/"> <xsl:variable name="rainbow"> <color>red</color> <color>blue</color> <color>green</color> </xsl:variable>
1
3684
by: Bartek | last post by:
Hello This is my problem: It consider xml 2 xml conversion. source document had unknown structure (xhtml), xslt must process every node, attribute, text, comments etc. from source and write in destination file. During that process i must catch some nodes (e.g. <input> position of this node in XML tree is unknown )and change the value attribute. The destination xml file must be the exact copy of source file + changes on
1
2046
by: inquirydog | last post by:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt? document("document.xml")//a/@b For the following sample document: <root> <a b="1" />
4
1658
by: titanandrews | last post by:
Hi, I have ran into a situation that I think should be possible, but I am fairly new to XSLT so maybe not. Suppose I have the following document <ROOT> <FOO name="A"> <CHILD name="B"/> </FOO>
3
2478
by: Jason S | last post by:
Hello Group, I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator) and saw that it works just fine. Now what I mean by not working is that it just silently fails to produce the expected output... no exceptions are being thrown. Xselerator uses msxml 3 so it's not really helping me see the problem in .net 1.1. ...
1
2419
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT stylesheets, that generates .NET assemblies) 2. Performance improvements in the XslCompiledTransform
3
9613
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
0
10137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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
9927
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,...
1
7360
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
5268
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3914
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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.