This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Inserting a file into another


Hi Robert,

> I have one xml file that I would like to insert into another XML
> file. How do I do this?

In your sample, you have an element called Insert_other_file_here.
When you find that element, you want to insert a copy of the content
of b.xml.  You can get hold of b.xml through the document() function:

  document('b.xml')

And you can make a copy of its content with xsl:copy-of:

  <xsl:copy-of select="document('b.xml')" />

You can match Insert_other_file_here with a template, so that when the
element is encountered, the document is copied in its place:

<xsl:template match="Insert_other_file_here">
  <xsl:copy-of select="document('b.xml')" />
</xsl:template>

For all other elements in a.xml, you just want to insert a copy of
that particular element (and presumably its attributes) and then move
on to process its content.  You should probably use the identity
transform for this, i.e.:

<xsl:template match="node()|@*">
   <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
   </xsl:copy>
</xsl:template>

This matches any node, copies the node, then applies templates to the
attributes and children of the node... which are matched by the
template, which copies the node, then applies templates to the
attributes and children of the node... which are matched by the
template... and so on recursively down the tree.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]