ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stin...@sas.upenn.edu
Subject Re: "include" equivalent in ant?
Date Mon, 11 Dec 2000 16:42:16 GMT
Here is one way to write an xinclude processor in XSL; it's coded such
that the name of the document element in subfiles is irrelevant.  Only
the child nodes of the subfile document element are copied.

xinclude.xsl:
=============

<xsl:stylesheet version="1.0" 
  xmlns:xinclude="http://www.w3.org/1999/xinclude"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>

<xsl:template match="xinclude:include">
  <xsl:apply-templates select="document(@href)/*/*"/>
</xsl:template>

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

</xsl:stylesheet>


test.xml:
=========

<project xmlns:xinclude="http://www.w3.org/1999/xinclude">
  <target n="main.1"/>
  <xinclude:include href="sub.ant"/>
  <target n="main.2"/>
</project>


sub.ant:
========
<include-wrapper>
  <target n="sub.1"/>
  <target n="sub.2"/>
</include-wrapper>


output (with Saxon 5.5.1):
==========================

<?xml version="1.0" encoding="utf-8"?>
<project xmlns:xinclude="http://www.w3.org/1999/xinclude">
   <target n="main.1"/>
   <target n="sub.1"/>
   <target n="sub.2"/>
   <target n="main.2"/>
</project>

 Steve

Mime
View raw message