citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

xml2sexp.xsl (1069B)


      1 <?xml version="1.0" encoding="utf-8"?>
      2 <!--$Id: xml2sexp.xsl 4047 2006-08-11 19:11:17Z tv.raman.tv $-->
      3 <!--
      4 Author: T. V. Raman
      5 Copyright:GPL
      6 Description:Convert XML to a Lisp S-expression.
      7 Goal: Replace Emacs' xml-parse.el with equivalent functionality
      8 Shortcomings: Quotes in  PCDATA will be lost
      9 Still very slow, possibly write a native  libxml2 app?
     10 -->
     11 
     12 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     13   version="1.0">
     14   
     15   <xsl:output method="text"/>
     16   <xsl:template match="text()">
     17     <xsl:variable name="text" select="normalize-space()"/>
     18     <xsl:if test="$text">
     19       "<xsl:value-of select="$text"/>"
     20     </xsl:if>
     21   </xsl:template>
     22   
     23   <xsl:template match="*">
     24     (<xsl:choose><xsl:when test="@*">(<xsl:value-of select="name()"/><xsl:apply-templates select="@*"/>)</xsl:when>
     25       <xsl:otherwise><xsl:value-of select="name()"/></xsl:otherwise></xsl:choose><xsl:apply-templates/>)
     26   </xsl:template>
     27   
     28   <xsl:template match="@*">
     29     (<xsl:value-of  select="name()"/> . "<xsl:value-of select="."/>")
     30   </xsl:template>
     31 </xsl:stylesheet>