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

  • SEARCH
  • Home
  • 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 521959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:18:17+00:00 2026-05-13T08:18:17+00:00

I’m working on a XSLT transformation that consists on merging two XML and then

  • 0

I’m working on a XSLT transformation that consists on merging two XML and then transform the result using another template. The idea is that depending on a field of the original XML file, the secong XML changes. For example:

<?xml version="1.0" encoding="UTF-8"?>
<data>
 <information>
  <stmtinfo>
   <type>80</type>
   <language>2</language>
   <clientnum>15907</clientnum>
   <clientname>bogus</clientname>
   <clientaddress>1401 Barnacle Street, Miami, Fl</clientaddress>
  </stmtinfo>
 </information>
</data>

depending on the value of the language node (let’s call it LANG), a file callled language{LANG}.xml should appended. The content of those files is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<labels>
 <l1001>cliente</l1001>
 <l1002>moneda de referencia</l1002>
</labels>

into something like this:

<?xml version="1.0" encoding="UTF-8"?>
<document>
 <information>
  <stmtinfo>
   <type>80</type>
   <language>2</language>
   <clientnum>15907</clientnum>
   <clientname>bogus</clientname>
   <clientaddress>1401 Barnacle Street, Miami, Fl</clientaddress>
  </stmtinfo>
 </information>
 <labels>
  <l1001>cliente</l1001>
  <l1002>moneda de referencia</l1002>
 </labels>
</document>

And the result of that should be transformed. I have created the following template to do the merge:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xalan="http://xml.apache.org/xalan" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:java="http://xml.apache.org/xalan/java/java.lang" xmlns:xfc="http://www.metafocus.no/digiforms/component">
 <xsl:template match="data">
  <document>
   <xsl:call-template name="copy"/>
   <xsl:variable name="label_file_name" select="concat('Labels_',information/stmtinfo/language,'.xml')"/>
   <xsl:variable name="labels">
    <xsl:copy-of select="document($label_file_name)"/>
   </xsl:variable>
   <xsl:for-each select="xalan:nodeset($labels)/node()">
    <xsl:call-template name="copy"/>
   </xsl:for-each>
  </document>
 </xsl:template>
 <xsl:template name="copy">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>

If I user that template, I obtain the following:

<?xml version="1.0" encoding="UTF-8"?><document xmlns:xfc="http://www.metafocus.no/digiforms/component" xmlns:java="http://xml.apache.org/xalan/java/java.lang" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xalan="http://xml.apache.org/xalan"><data>
 <information>
  <stmtinfo>
   <type>80</type>
   <language>2</language>
   <clientnum>15907</clientnum>
   <clientname>bogus</clientname>
   <clientaddress>1401 Barnacle Street, Miami, Fl</clientaddress>
  </stmtinfo>
 </information>
</data><labels>
 <l1001>cliente</l1001>
 <l1002>moneda de referencia</l1002>
</labels></document>

Which seems correct. But if I invocated from other template, to process the resulting XML

<xsl:template match="/">
 <xsl:variable name="link1">
  <xsl:apply-templates mode="link1" select="node()"/>
 </xsl:variable>
 <xsl:value-of select="xalan:nodeset($link1)"/>
</xsl:template>

I’m obtaining the following

80
2
15907
bogus
1401 Barnacle Street, Miami, Fl

So it seems that the merge does not work correctly, since if I convert the result to a nodeset, the node “labels” disappears. What I’m doing wrong?

Thank you very much.

Jose

  • 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-13T08:18:17+00:00Added an answer on May 13, 2026 at 8:18 am

    Why are you doing a two-pass transform in the first place? It seems to me that if you just put:

    <xsl:variable name="labels" select="document(concat(
       'Labels_', 
       /data/information/stmtinfo/language, 
       '.xml'))"/>
    

    at the top of your document, then you can reference $labels explicitly in your templates. The result of the first pass of your transform isn’t different enough in structure from the source XML that you’re really gaining anything but complexity from doing it in two passes.

    That said, the problem in the transform as written is almost certainly that you’re doing this:

    <xsl:value-of select="xalan:nodeset($link1)"/>
    

    instead of this:

    <xsl:copy-of select="xalan:nodeset($link1)"/>
    

    The value of an element is the concatenation of all of its descendant text nodes, and that’s what you’re getting in your output.

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

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.