0

I have one XML file that I want to toggle between what content should be handled by my xslt file. Example:

<code>
    <manual>
        <use>1</use>
    </manual>
    <generated>
        <use>0</use>
    </generated>
    <doc>
        <localpath>content.xml</localpath>
    </doc>
</code>

Then the content.xml has the same tags, i.e. generated and manual, where the data to be interpreted is. I have searched around and found this snippet:

<xsl:variable name="messages" select="doc"/>
<xsl:apply-templates select="document('$messages')"/>

The variable messages is populated correctly but the doc does not seem to be loaded. Or am I looking at it wrong should it be seen as content.xml is loaded into the <doc> tag so the navigation starts there and moves forward?

I am quite new to XSLT so please bear with me if this is obvious.

1 Answer 1

2

That should be document($messages) not document('$messages'). I would also expect

<xsl:variable name="messages" select="doc/localpath"/>

That leaves a question about what "content.xml" is relative to: is it relative to the source document, or to the stylesheet?

As to your question "Or am I looking at it wrong should it be seen as content.xml is loaded into the tag so the navigation starts there and moves forward?" - you are using terminology here which simply has no meaning in XSLT (like "loading a string into a tag" and "navigation moving forward"). So it looks to me as if you are trying to build a mental model of how XSLT works that has little basis in reality, and if that's the case, I would strongly suggest doing more reading before you write more code.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, thank you. Before I mark it correct. I have searched around an only found documents about combining xml. I have one xml document where I create a small webpage from. But I would like to have ax xml file that defines which elements of another xml file should be interpreted. Is this just conceptually wrong?
It's a perfectly respectable use case to have one document that references other documents by (typically relative) URI, and even that references parts of other documents by ID values or by XPath expressions. (But for the last case, interpreting XPath expressions read from a source document, you'll either need XSLT 3.0, or vendor extensions.) Again: read some XSLT books, and you will find such use cases discussed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.