Skip to content

Instantly share code, notes, and snippets.

@bortzmeyer
Created April 19, 2019 14:01
Show Gist options
  • Select an option

  • Save bortzmeyer/e50bbc877020e5eeff5eaa4b29bd91cc to your computer and use it in GitHub Desktop.

Select an option

Save bortzmeyer/e50bbc877020e5eeff5eaa4b29bd91cc to your computer and use it in GitHub Desktop.
Playing with XML
% cat toto.xml
<?xml version="1.0" encoding="utf-8"?>
<p>foo <b>bar</b> : quz</p>

% cat convert.xsl
<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE stylesheet [
<!ENTITY newln "&#xA;">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'>

  <xsl:output method="text" encoding="UTF-8"/> 

  <xsl:template match="p">
    <xsl:text>&newln;</xsl:text><xsl:apply-templates/><xsl:text>&newln;</xsl:text>
  </xsl:template>

  <xsl:template match="b">
    <xsl:text>**</xsl:text><xsl:apply-templates/><xsl:text>**</xsl:text>
  </xsl:template>

  <xsl:template match="/">
     <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>

% xsltproc convert.xsl toto.xml           

foo **bar** : quz

There is a non-breaking space in the source, before the colon, and it is of course outputted as-is.

@bortzmeyer

Copy link
Copy Markdown
Author
% cat toto2.xml
<?xml version="1.0" encoding="utf-8"?>
<div>
   <p>foo <b>bar</b> : quz</p>
</div>
 
% xsltproc convert.xsl toto2.xml 

   
foo **bar** : quz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment