<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text" encoding="ISO-8859-1"/>
  
  <xsl:template match="/">
    <xsl:variable name="projects" select="projects/project"/>
    <xsl:choose>
      <xsl:when test="$projects">
        <xsl:text>digraph {&#xA;</xsl:text>
        <xsl:for-each select="$projects">
          <xsl:variable name="project" select="document(.,/)/project"/>
          <xsl:variable name="name" select="$project/id"/>
          <xsl:for-each select="$project/dependencies/dependency">
            <xsl:text>"</xsl:text>
            <xsl:value-of select="$name"/>
            <xsl:text>" -> "</xsl:text>
            <xsl:choose>
              <xsl:when test="name">
                <xsl:value-of select="name"/>
              </xsl:when>
              <xsl:when test="id">
                <xsl:value-of select="id"/>
              </xsl:when>
              <xsl:when test="groupId">
                <xsl:value-of select="groupId"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>Dependency without name in </xsl:text>
                <xsl:value-of select="$name"/>
                <xsl:text> (#</xsl:text>
                <xsl:value-of select="position()"/>
                <xsl:text>)</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:text>";&#xA;</xsl:text>
          </xsl:for-each>
        </xsl:for-each>
        <xsl:text>}&#xA;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate="yes">
          <xsl:text>No project.xml files&#xA;</xsl:text>
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>