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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL: Including child document, THEN matching it's elements 1

Status
Not open for further replies.

csteinhilber

Programmer
Aug 2, 2002
1,291
US
I have an XML file that describes data to present in HTML. But one of the possible elements is what we're calling a "super element"... it's basically an node that describes another XML file that would need to be included into the HTML presentation.

So, for example, the base XML file is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<datapacket>
   [COLOR=#ff0000]<otherdata>
       <dataset>full</dataset>
       <headers>true</headers>
   </otherdata>[/color]
   <datarow>
       <element1>1</element1>
       <element2>2</element2>
       <element3>3</element3>
   </datarow>
   <datarow>
       <element1>4</element1>
       <element2>5</element2>
       <element3>6</element3>
   </datarow>
</datapacket>

The otherdata element is our "super element". Based on it's attributes, it determines another XML file to include into this base XML.

So the super element might define the inclusion of data2.xml, such that:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<datapacket>
   <datarow>
       <element1>7</element1>
       <element2>8</element2>
       <element3>9</element3>
   </datarow>
</datapacket>

The actual inclusion of the additional XML file is pretty straight-forward:
Code:
<xsl:template match="otherdata">
    <!-- some if/when/test to determine the name of the additional xml file -->
    <xsl:value-of select="document('data2.xml')" />
</xsl:template>

The problem I'm having is... I then need to process the entire XML dataset with the stylesheet. In other words, if I have:
Code:
<xsl:template match="datarow">
    :
</xsl:template>
it needs to match both the datarow elements in the original XML and the datarow elements in the data2.xml nodes that just got included.

Anybody have any ideas? Run two XSLTs, maybe... but what would they look like?

Any help would be appreciated!

Thanks,
-Carl
 
Seems easy enough to me. Your XSLT can determine if this <otherdata> exists, and do an
Code:
<xsl:apply-templates select="document('data2.xml')/datapacket" />

After that, then apply-templates to the elements in the input document.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top