Skip to content

Instantly share code, notes, and snippets.

@pfhawkins
Forked from nicferrier/flatten.xslt
Created January 24, 2012 21:16
Show Gist options
  • Save pfhawkins/1672763 to your computer and use it in GitHub Desktop.
Save pfhawkins/1672763 to your computer and use it in GitHub Desktop.
flatten
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:re="http://exslt.org/regular-expressions"
extension-element-prefixes="str regexp"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output mode="text" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//table//tr" mode="variables">
<xsl:sort/>
</xsl:apply-templates><xsl:apply-templates select="//table//tr"/></xsl:template>
<xsl:template match="tr">
<xsl:if test="count(td) = 3">
<xsl:value-of select="td[1]"/>|<xsl:value-of select="td[2]"/>|<xsl:value-of select="td[3]"/><xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="tr" mode="variables">
<xsl:if test="count(td) = 3">
<xsl:for-each select="td">
<xsl:if test="re:test(., '.*\$\{[A-Za-z0-9]+\}.*')">variable|<xsl:value-of select="re:replace(., '.*\$\{([A-Za-z0-9]+)\}.*', '', '\1')"/>|
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment