Thaispookie
Thaispookie

Reputation: 19

Joining two complex XSLT variables into a new one

I like to import or include two or more externals xsl's to my main xsl.

Each xsl has an dictonary

<my:dictonary>
    <my:entrys lang="en">
        <firstname>First Name</firstname>
        <lastname>Last Name</lastname>
    </my:entrys>
</my:dictonary>

<my:dictonary>
    <my:entrys lang="de">
        <firstname>Vorname</firstname>
        <lastname>Nachname</lastname>
    </my:entrys>
</my:dictonary>

Now i like to have all this in one variable

 <my:dictonary>
    <my:entrys lang="en">
        <firstname>First Name</firstname>
        <lastname>Last Name</lastname>
    </my:entrys>
    <my:entrys lang="de">
        <firstname>Vorname</firstname>
        <lastname>Nachname</lastname>
    </my:entrys>
</my:dictonary>

Is this possible with xslt 1.0 without any extensions?

Thanks

T.S

Upvotes: 0

Views: 113

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117140

First, what you show us are not "two complex XSLT variables" but two XML node-sets. You can combine them easily into a single variable, for example like this:

<xsl:variable name="en" select="document('file1.xml')/dictonary/entrys" />
<xsl:variable name="de" select="document('file2.xml')/dictonary/entrys" />
<xsl:variable name="common" select="$en | $de" />

Note that I have removed the my: prefix from both source node-sets, since (a) it is not necessary and (b) you haven't provided a namespace for it.

The resulting $common variable has the following content:

<entrys lang="en">
        <firstname>First Name</firstname>
        <lastname>Last Name</lastname>
</entrys>
<entrys lang="de">
        <firstname>Vorname</firstname>
        <lastname>Nachname</lastname>
</entrys>

and the data type of the content is node-set - so you can use it in a <xsl:for-each> or apply templates to it, without requiring the EXSLT node-set() function..

Upvotes: 2

Related Questions