I'm unmarshaling a couple of large XML files.
they have the common part and I decided to write the common parts in separate XML file and then include it using xi:include tag.
it looks like this:
<tag1>
<tag2>
</tag2>
<tag3>
</tag3>
<xi:include href = "long/common/part/of/partial/xml/file1"/>
<xi:include href = "long/common/part/of/partial/xml/file2"/>
</tag1>
at this moment I would like to parametrize the long/common/part.
I tried to define a variable using xsl:variable like this
<xsl:variable name="test">
"long/common/part/of/partial/xml/"
</xsl:variable>
but the assigning value to href was a problem, neither the
<xi:include href = "{$test}"/>
or
<xi:include href = <xsl:value-of select="test"/>
wasn't working. Is there a way to assign value to XML attribute?
You're mixing XInclude, XSLT, and ad-hoc
{$var}syntax (not part of XML) here. What you can do to parametrize ahrefvalue in XInclude elements is to use an entity reference (XML's and SGML's mechanism for text substitution variables among other things):where
href-valuemust be bound to the stringlong/common/part/of/partial/xml/file1either programmatically, or (preferably) by declaring it in the prolog eg:However, since now you're using entity references anyway, you can achieve just the same with just entities, and without XInclude at all:
This pulls the content of long/common/part/of/partial/xml/file1 into the
common-partentity, then references that value in content, with the XML parser treating the document as if the replacement value forcommon-part(eg. whatever is stored inlong/common/part/of/partial/xml/file1) had been specified directly in the document.Hope this isn't too confusing; there's a general explanation how entities in XML and SGML work in this answer