Adjusting URI's in HTML Output from XSLT

Discussion in 'XML' started by Don Garrett, Oct 28, 2003.

  1. Don Garrett

    Don Garrett Guest

    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?

    --
    Don
     
    Don Garrett, Oct 28, 2003
    #1
    1. Advertising

  2. 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



    "Don Garrett" <> wrote in message
    news:...
    > 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?
    >
    > --
    > Don
    >
     
    Dimitre Novatchev, Oct 28, 2003
    #2
    1. Advertising

  3. Don Garrett

    Don Garrett Guest

    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 Novatchev wrote:
    > 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
    >
    >
    >
    > "Don Garrett" <> wrote in message
    > news:...
    >
    >> 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?
    >>
    >>--
    >>Don
    >>

    >
    >
    >
     
    Don Garrett, Oct 29, 2003
    #3
  4. Don Garrett

    Don Garrett Guest

    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 Novatchev wrote:
    > 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
    >
    >
    >
    > "Don Garrett" <> wrote in message
    > news:...
    >
    >> 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?
    >>
    >>--
    >>Don
    >>

    >
    >
    >
     
    Don Garrett, Oct 29, 2003
    #4
  5. "Don Garrett" <> wrote in message
    news:...
    > 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
     
    Dimitre Novatchev, Oct 29, 2003
    #5
  6. Don Garrett

    Don Garrett Guest

    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!

    Dimitre Novatchev wrote:
    > "Don Garrett" <> wrote in message
    > news:...
    >
    >> 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
    >
    >
    >
    >
    >
     
    Don Garrett, Oct 31, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Harris
    Replies:
    0
    Views:
    6,482
    Simon Harris
    May 10, 2005
  2. Stanimir Stamenkov
    Replies:
    1
    Views:
    2,531
    Stanimir Stamenkov
    Aug 17, 2005
  3. Pavel
    Replies:
    2
    Views:
    1,722
    Peter Flynn
    Aug 4, 2004
  4. etheriau
    Replies:
    1
    Views:
    699
    Pavel
    Aug 23, 2004
  5. Turbo
    Replies:
    2
    Views:
    179
    Turbo
    Nov 1, 2006
Loading...

Share This Page