Adjusting URI's in HTML Output from XSLT

D

Don Garrett

I have an XML document at the root of a directory tree that contains
relative URIs to resources in a directory tree.

During XSLT processing, these URI's can be used without any problems
to access the various documents in the tree. However, when generating
HTML output, the output <a href=""> tags need to be adjusted for the
location of the document that is displaying them.

I need to use relative URLs, since the documents need to be
translated in a variety of locations without modification.

file://foo/bar/resources.xml
http://server/resources.xml
http://server/foo/bar/resources.xml

resources.xml looks something like this:

<resources>
<resource>
<name>Foo</name>
<uri>subdir/foo.xml</uri>
</resource>
</resources>


I have an <xsl:template> to expand this to:

<a href="subdir/foo.xml">Foo</a>

However, I get that exact expansion, even if I am expanding a
document that is already in subdir, subdir1, or subdir2.

I would like to instead have it expand differently, depending on the
location of the document that is being expanded.

If the document is in:

subdir: <a href="foo.xml">Foo</a>
subdir2: <a href="../subdir/foo.xml">Foo</a>
subdir2/subsubdir: <a href="../../subdir/foo.xml">Foo</a>
etc.

What is the best approach to solving this problem? This is my first
large scale use of XML/XSLT, but I have a hard time believing that this
isn't a common issue.

How do other people solve this problem?
 
D

Don Garrett

I appreciate the reference, but I can't make use of the mechanisms
you are referring too, since it's based on vendor specific tools.

I'm starting to wonder if I can use external unparsed entities and
the xslt function unparsed-entity-uri(). It does appear to adjust
relative links automatically, but the process of using entities appears
really awkward overall.

Dimitre said:
See the thread "Creating a new relative path for a new base directory from
an old one (Was: Re: XSLT Software Tool) "
in comp.text.xml and microsoft.public.xml from 2003-05-02 :

http://groups.google.com/groups?hl=...mi2te2naletj9aprqcfdqadi0u%404ax.com&rnum=503



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
D

Don Garrett

I appreciate the reference, but I can't make use of the mechanisms
you are referring too, since it's based on vendor specific tools.

I'm starting to wonder if I can use external unparsed entities and
the xslt function unparsed-entity-uri(). It does appear to adjust
relative links automatically, but the process of using entities appears
really awkward overall.

Dimitre said:
See the thread "Creating a new relative path for a new base directory from
an old one (Was: Re: XSLT Software Tool) "
in comp.text.xml and microsoft.public.xml from 2003-05-02 :

http://groups.google.com/groups?hl=...mi2te2naletj9aprqcfdqadi0u%404ax.com&rnum=503



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
D

Dimitre Novatchev

Don Garrett said:
I appreciate the reference, but I can't make use of the mechanisms
you are referring too, since it's based on vendor specific tools.

You are wrong here -- FXSL is not a vendor-specific tool. It is an open
source xslt template library. It uses pure XSLT 1.0 or XSLT 2.0.

The XSLT 1.0 uses a single extension function -- exslt:node-set().

EXSLT is implemented by most of the major XSLT processors (MSXML4, .Net
xsltTransform, Saxon, Xalan (both the Java and C implementation), JD,
xsltLib/xsltProc, 4xslt, sablotron, etc. ...).

Therefore, the solution will run unmodified on anyone of this large group of
XSLT processors.

The XSLT 2.0 version of FXSL does not use any extension functions at all.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
D

Don Garrett

My apologies. I saw references to VB, etc in the posts and was
worried. When I went to the FXSL downloads site, I saw the MSXML4
extensions, and looked no further.

I've now downloaded FXSL, and will be trying it out shortly.

Thanks!
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top