Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:59:41+00:00 2026-05-26T14:59:41+00:00

Within an XSL stylesheet, I’m trying to use the document() function with a relative

  • 0

Within an XSL stylesheet, I’m trying to use the document() function with a relative path to an xml file (which should be possible if I understand the XSLT specs correctly), but for some reason it doesn’t seem to load the file. The same code using an absolute URI works as expected. The XML file I’m trying to load is in the same folder as the stylesheet.

The question is, am I missing something in regards to how the document() function in the Coldfusion 8 XSLT parser resolves relative paths? I’m using XmlTransform to invoke the XSLT parser in my CF component.

The folder structure (simplified, docroot = domain, e.g. http://www.example.com/):

docroot/html/xsl/stylesheet.xsl 
docroot/html/xsl/translations.xml
docroot/backend.cfc

The XSLT that calls the document function:

<h1>We should have hello after this text</h1>

<xsl:for-each select="document('translations.xml')">
    <h2>hello</h2>
</xsl:for-each>

<h1>We should have hello before this text</h1>

In the above code, if I replace document('translation.xml') with document('http://www.example.com/html/xsl/translation.xml'), the code works as expected. However, hard coding the domain into the statement is what I would like to avoid as it makes the stylesheet less portable.

The XML I’m trying to load:

<?xml version="1.0" encoding="utf-8"?>
<translations>
    <fi>
        <insured>Vakuutettu</insured>
    </fi>
    <se>
        <insured>Försäkrad</insured>
    </se>
</translations>

The code in the ColdFusion component backend.cfc, which starts the XSL parser:

...
<cfoutput>#XmlTransform(obj, xsltProductTable04, xslParameters)#</cfoutput>
...

xsltProductTable04 is a variable which points to the stylesheet I’m loading, and it has the value html/xsl/stylesheet.xsl. Could it make a difference that I’m loading the stylesheet using a URI relative to the cfc component?

Update

As per Dimitre Novatchev’s suggestion, I tried removing every section of the URL step by step (e.g. /html/xsl/translation.xml, /xsl/translation.xml etc.), but none of the combinations work. Even tried alternatively with and without the forward slash in the beginning of the URL’s.

Update 2

My current workaround to this issue is to build an absolute URL outside of the stylesheet and then pass it in as an argument to the stylesheet. This works, and in my current project actually turns out to be a better solution because it allows me to simplify the XSL, since I don’t need to care about selecting the correct language inside the XSL anymore. But it’s still only a workaround to the original issue. If anyone has more info on why CF behaves as it does, then I’d be happy to hear it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:59:42+00:00Added an answer on May 26, 2026 at 2:59 pm

    I’ve not done much with XSLT or xmlTransform(), but I read the docs, which say this:

    If the XSLT code contains include statements with relative paths, ColdFusion resolves them relative to the location of the XSLT file, or for an XSL string, the location of the current ColdFusion page.

    And I tested both of those, and they work fine. What seems to be your problem is that you’re passing the XSL as a string to xmlTransform(), so when the XSLT processor sees the reference to “translations.xml”, it has to look at it relative to the calling code, rather than relative to the original XML file (which as far as it knows could have been anywhere: all it received was a string, after all).

    So I can make your code work by making one of two mods:

    First one could pass in the file PATH, eg:

    XmlTransform(obj, expandPath("xsl/stylesheet.xsl"), xslParameters)
    

    That way the xmlTransform() call knows where the XSL file is, so knows how to work out paths relative to the XSL file itself.

    Or secondly, make the ref to translations.xml in the XSL file relative to the code not the XSL file, eg:

    <xsl:for-each select="document('xsl/translations.xml')">
    

    Both of those approaches works for me. I think the first one is more transportable, though.

    Make sense?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within an XSL stylesheet, I'm trying to use the document() function with a relative
I'm starting to use lxml in Python for processing XML/XSL documents, and in general
I have an xml file which describes (among other things) elements with attribute values
I have an interesting problem with XSL. We have an XML Input file that
I'm attempting to apply an XSL transform to an XML file inside an SSIS
Is it possible to have XML-embedded JavaScript executed to assist in client-side (browser-based) XSL
Can i use a Select within a concat in xslt? eg <xsl:for-each select=root/OrderItems/lineitem> <xsl:element
My problem is that my XML document contains snippets of XHTML within it and
I needed to use XSL to generate simple plain text output from XML. Since
Within a foreach loop i want to use preceding-sibling:: <for-each..> <xsl:sort select=type/> <xsl:when test=preceding-sibling::data[1]/type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.