ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 36890] - concat task: add support for XML files
Date Thu, 06 Oct 2005 13:52:42 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=36890>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=36890





------- Additional Comments From ddevienne@lgc.com  2005-10-06 15:52 -------
Yes, I understood that part. You iterate over the fileset(s) with Ant-Contrib's 
<for>, generating a small XML file that only lists the files to process (one 
per element). You feed this file into an XSL that process this file, applying a 
template rule to each file element to document() load it, and copy its 
elements. Here's an example:

    <echo file="${javadocs}/index.xml"
>&lt;?xml version="1.0" ?&gt;
&lt;javadocs last-modified="${CVS_DATE}"
          root="${docsroot}"&gt;
</echo>

    <ac:for param="name" list="${docdirs}">
      <ac:sequential>
        ...
        <echo file="${javadocs}/index.xml" append="true"><![CDATA[
          <module name="@{name}"
                  tag="${@{name}-tag}"
                  errors="${@{name}-errors}"
                  warnings="${@{name}-warnings}"
                  versions="${@{name}-versions}"
                  packages="${@{name}-packages}" />
        ]]></echo>
      </ac:sequential>
    </ac:for>

    <echo file="${javadocs}/index.xml" append="true">
      &lt;/javadocs&gt;
    </echo>

    <!-- Inject the errors/warnings stats into index.xml -->
    <style in="${javadocs}/index.xml" out="${javadocs}/index2.xml"
           style="config/javadocs-addchecks.xsl" />

    <!-- The index.html listing all Modules and the Javadocs links -->
    <style in="${javadocs}/index2.xml" out="${javadocs}/index.html"
           style="config/javadocs-index.xsl">
      <param name="cycletitle" expression="${cycletitle}" />
    </style>

    ...


And here's an example XSL to inject something into the document. You simply 
need a variation that copies the content of the xmlroot variable into the 
result document instead of copying the input element with additional nodes.

--DD

<?xml version="1.0" encoding="UTF-8"?>

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

  <xsl:output method="xml" encoding="UTF-8" indent="yes" />

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

  <!-- ================================================= -->
  <xsl:template match="module">
    <xsl:param name="javadocs" select="'../build/javadocs'" />

    <xsl:variable name="docsdir" select="concat($javadocs, '/', @name)" />
    <xsl:variable name="xmlfile" select="concat($docsdir, '/checkstyle.xml')" />
    <xsl:variable name="xmlroot" select="document($xmlfile)/checkstyle" />

    <xsl:copy>
      <!-- copy attributes -->
      <xsl:copy-of select="@*" />

      <!-- insert checktyle element -->
      <xsl:choose>
        <xsl:when test="$xmlroot">
          <xsl:variable name="errorcount" select="count($xmlroot/file/error)" />
          <xsl:variable name="totalfiles" select="count($xmlroot/file)" />

          <checkstyle errorcount="{$errorcount}"
                      errorfiles="{count($xmlroot/file[error])}"
                      totalfiles="{$totalfiles}"
                      errperfile="{$errorcount div $totalfiles}"
                      fullreport="{$xmlfile}" />
        </xsl:when>
        <xsl:otherwise>
          <checkstyle report="{$xmlfile}" />
        </xsl:otherwise>
      </xsl:choose>

      <!-- copy nested elements -->
      <xsl:apply-templates select="node()" />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message