tags:

views:

36

answers:

2

Is there any trick to match two XML by one XSLT? I mean the way I can apply XSLT to a parameter passed.

For example (I missed declarations to be short). XML1: XML to be transformed:

<myData>
   <Collection>

   </Collection>
</myData>

XSLT need to be applied to the previous XML:

<xsl:param name='items' />
<xsl:template match='Collection'>
    <!-- some transformation here -->
</xsl:template>

XML2: XML data passed as the parameter 'items':

<newData>
   <Item>1</Item>
   <Item>2</Item>
   <Item>3</Item>
</newData>

And I need to create a set of nodes in the 'Collection' node in XML1 for each 'Item' element in XML2 using XSLT. And I do not know what XML2 contains exactly at design time. It is generated at runtime, so I can't place it inside XSLT, I know only its schema.

+1  A: 

(1). You could generate the XSLT instead of using a static XSLT:

transform xml2 with xslt1 which leads to xslt2
transform xml1 with xslt2 which leads to the desired output

(2). You could use the document() function to load xml2. This requires xml2 to be persisted to disk or to be accessible by a uri.

      <xsl:copy-of select="document('xml2.xml')//newData" />  
Jan Willem B
The second variant is more suitable for me, thank you.
brain_pusher
+1  A: 

Read about and use the standard XSLT function document().

Dimitre Novatchev