This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes How to pass string instead of xml in xsl Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "How to pass string instead of xml in xsl" Watch "How to pass string instead of xml in xsl" New topic
Author

How to pass string instead of xml in xsl

Rizwan Qadri
Ranch Hand

Joined: May 28, 2007
Posts: 40
Hi all,

In my current project i have to combine different xml into one xml. so that i have used one xsl file. In this i have hard coded the xml file. But i want that file come as a string . how i can do this.


Code.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<!-- load the merge file -->
<xsl:variable name="emps" select="document('employeeAddresses.xml')"/>
<xsl:template match="/">
<employees>
<xsl:for-each select="employees/employee">
<!-- cache the employee's ID -->
<xsl:variable name="id">
<xsl:value-of select="@id"/>
</xsl:variable>
<!-- copy the child nodes -->
<employee>
<xsl:copy-of select="child::*"/>
<!-- copy the children of the matching
employee node
from the merge file -->
<xsl:copy-of select="$emps/employees/employee[@id=$id]/child::*"/>
</employee>
</xsl:for-each>
</employees>
</xsl:template>
</xsl:stylesheet>



Thanks,

rizwan
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

Do you mean that you want the file name to be a variable instead of a constant?
Rizwan Qadri
Ranch Hand

Joined: May 28, 2007
Posts: 40
Yes
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to pass string instead of xml in xsl
 
Similar Threads
XSLT : Grouping Child Nodes...
Colon inside tag and xsl referring two xml
possible to create dynamically named nodes via xslt?
How to insert a structure into XML
Parameter passing in xslt transformation