By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,723 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,723 IT Pros & Developers. It's quick & easy.

including xml file in xslt?

P: n/a
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?)

May 8 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
> 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.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
May 8 '06 #2

P: n/a

Elhanan wrote:
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.

May 8 '06 #3

P: n/a
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.

May 8 '06 #4

P: n/a
never mind got it, i should have place
setNameSpaceAware()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!

May 8 '06 #5

P: n/a
Elhanan wrote:
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
--
XML FAQ: http://xml.silmaril.ie/
May 8 '06 #6

P: n/a
yea but how do i xpath on that variable?

May 10 '06 #7

P: n/a
Elhanan wrote:
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.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
May 10 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.