LG to dot transformation

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      version="1.1">
  <xsl:output method="text" version="1.0" encoding="ISO-8859-1"
          omit-xml-declaration="no" indent="yes"/>
<xsl:template match="/LG">
      <xsl:text>digraph G { 
</xsl:text>
      <xsl:apply-templates select="relations/relation"/>
      <xsl:text>}
</xsl:text>
</xsl:template>

<xsl:template match="relations/relation" name="relation">
  <xsl:for-each select="source">
   <xsl:variable name="sourceidref" select="@idref"/>
   <xsl:variable name="targetidref" select="../target/@idref"/>
   <xsl:variable name="targetname" 
     select="../../../lexitems/lexitem[@lexid=$targetidref]"/>
   <xsl:variable name="sourcename" 
      select="../../../lexitems/lexitem[@lexid=$sourceidref]"/>
   <xsl:variable name="translate_from">"</xsl:variable>
   <xsl:variable name="translate_to">\"</xsl:variable>
   <xsl:text>"</xsl:text>
   <xsl:call-template name="replace-string">
      <xsl:with-param name="text" select="$sourcename"/>
      <xsl:with-param name="from" select="$translate_from"/>
      <xsl:with-param name="to" select="$translate_to"/>
   </xsl:call-template>
   <xsl:text>"  -&gt; "</xsl:text>
   <xsl:call-template name="replace-string">
      <xsl:with-param name="text" select="$targetname"/>
      <xsl:with-param name="from" select="$translate_from"/>
      <xsl:with-param name="to" select="$translate_to"/>
   </xsl:call-template>
     <xsl:text>" [label="</xsl:text>
     <xsl:value-of select="../@type"/> 
     <xsl:text>"];
</xsl:text>
  </xsl:for-each>
</xsl:template>

<xsl:template match="lexitems/lexitem/@lexid" 
     name="idrefresolve">
  <xsl:value-of select="../*"/>
</xsl:template>



<xsl:template name="replace-string">
  <xsl:param name="text"/>
    <xsl:param name="from"/>
     <xsl:param name="to"/>  
     <xsl:choose>
       <xsl:when test="contains($text, $from)">
         <xsl:variable name="before" 
                select="substring-before($text, $from)"/>
           <xsl:variable name="after" 
                select="substring-after($text, $from)"/>
           <xsl:variable name="prefix" 
                select="concat($before, $to)"/>

           <xsl:value-of select="$before"/>
           <xsl:value-of select="$to"/>
           <xsl:call-template name="replace-string">
              <xsl:with-param name="text" select="$after"/>
              <xsl:with-param name="from" select="$from"/>
              <xsl:with-param name="to" select="$to"/>
           </xsl:call-template>
         </xsl:when> 
         <xsl:otherwise>
           <xsl:value-of select="$text"/>  
         </xsl:otherwise>
      </xsl:choose>            
  </xsl:template>
</xsl:stylesheet>
Thorsten Trippel 2006-11-18