开发者

How to process XML file referenced in input XML using XSLT?

Suppo开发者_开发问答se I have in my input XML file a reference (URL) to another XML file. I'd like to process this referenced XML file as if it were the input of my stylesheet/template. How do I do that?


Use the standard XSLT document() function, like this:

<xsl:template match="someElementContainingURL">
 <xsl:apply-templates select="document(string(.))" mode="doc2"/>
</xsl:template>

In the example above, we suppose that in the source XML document an element named someElementContainingURL (substitute this by the actual element name in your specific XML document) contains the URL to a second document that you want to process.

Within the template matching someElementContainingURL we apply templates to the result of the document() function when passed as argument the string value of the current node. It is best to organize the processing of the second document in a different mode, so that identical node names and node types from the two documents can be processed by different templates, avoiding conflicts.


<xsl:copy-of select="document('document.xml')/rootnode/subnode" />
<xsl:copy-of select="document('http://example.com/document.xml')/rootnode/subnode" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜