Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need tips for merging multiple documents

Status
Not open for further replies.

peakco

Programmer
Sep 12, 2002
13
US
My goal is to merge an XHTML document that is acting like a template with peices from several XML documents. I'm open to any approach.

My current strategy is having an <insert> tag in the XHTML whereever the merge is to occur; for instance,

lots of xhtml code to keep
<insert href=&quot;contacts.xml&quot; xpath=&quot;//contact[@id='bob']&quot; />
more xhtml code to keep

When encountering the <insert> tag, I do something like

<xsl:apply-templates select=&quot;document(@href)/@xpath&quot; />

Where @xpath should be the contents of the attribute, not the &quot;@xpath&quot; itself. This is akin to a Javascript eval(@xpath).

Can it be done in XSLT?

 
My own answer. Yes and no. The No is because XML xpaths are fixed at compilation time. Since an XML variable isn't, you can not use it. (you can use a predicate of the form [$value=@name], but nothing more complicated).

The Yes: add an additional transform step. So the xhtml is first wrapped in xsl and the <insert> tags resolved to docuemnt(file.xml)/arbitarty-xpath. Pass two does the insert and resulting in the original xhtml with the inserted stuff.

Alternative is manipulating the DOM directly to resolve the insert tags, but that is not XML anymore.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top