including xml file in xslt?

E

Elhanan

hi..

i'm trying to figure out if i can include an extenal file of xml inside
xslt, what i need is a configuration file which xslt can query duing
transformation, (we are talking about a rather large document here.


i thought about using document function, since i'm gonna thiis called
about hunders of times i don't know the impact this would have on
performance (does xsll keeps opening closing a file?)
 
J

Joseph Kesselman

i thought about using document function, since i'm gonna thiis called
about hunders of times i don't know the impact this would have on
performance (does xsll keeps opening closing a file?)

Odds are that most XSLT processors will cache documents referenced by
document() -- it's the easiest way to implement some of the
unique-identity requirements. If you want to make sure it gets cached
you could do a single document() call and assign to a (global?) variable.
 
A

Andy Dingley

Elhanan said:
i thought about using document function, since i'm gonna thiis called
about hunders of times i don't know the impact this would have on
performance

The standards don't specify performance-critical behaviours like that -
so whatever you do, build a simple benchmark first and measure it. It
rarely takes long to do, in the overall project complexity.
 
E

Elhanan

thanks you mean assign it to a global variable and then do all my xpath
queries on that var? how can i do that?

now i have a much bigget problem, i'm trying to parse my xsl file with
xpath query, to remove certian bits, now i find out i cannot do any
xpath queries at all!

i look over at the samples and copied but still it doesn't work.
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
DocumentBuilder b= f.newDocumentBuilder();
org.w3c.dom.Document doc=b.parse("ATmap.xml");

XPathFactory xp=XPathFactory.newInstance();
XPath xpa=xp.newXPath();
xpa.setNamespaceContext(new MyNamespaceContext());

XPathExpression xe=xpa.compile("//foo:document");

Node when =(Node)xe.evaluate(doc,XPathConstants.NODE);
System.out.println(when);
}catch (Exception e){
e.printStackTrace();
}

and the xml is:
<?xml version='1.0'?>
<foo:document xmlns:foo="http://apache.org/foo"
xmlns:bar="http://apache.org/bar">
<bar:element>MyBar</bar:element>
</foo:document>

and yet i keep getting null!!, i'm going crazy here.
 
E

Elhanan

never mind got it, i should have place
setNameSpaceAware()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
P

Peter Flynn

Elhanan said:
thanks you mean assign it to a global variable and then do all my xpath
queries on that var? how can i do that?

<xsl:variable name="something" select="document('foo.xml')/stuff"/>

///Peter
 
J

Joe Kesselman

Elhanan said:
yea but how do i xpath on that variable?

If the variable contains a nodeset, you can use it as the root of an
XPath -- $foo/bar/baz[@murph] or whatever to start your search from the
nodes in variable $foo.

If it contains a Result Tree Fragment (RTF), you need to use the EXSLT
nodeset function (or whatever equivalent your processor supports) to
turn it into a nodeset first; then proceed as above.

Note that in XSLT 2.0, the distinction between those two goes away; any
expression that returned one or the other will return a Temporary Tree,
which can be used in expressions the way nodesets are in 1.0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top