Skip to content

Instantly share code, notes, and snippets.

@typekpb
Last active December 20, 2015 03:19
Show Gist options
  • Save typekpb/6062489 to your computer and use it in GitHub Desktop.
Save typekpb/6062489 to your computer and use it in GitHub Desktop.
xmlstarlet sel -C -t -m "messages" -m "note" -v "from" < sample.xml
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" version="1.0" extension-element-prefixes="exslt">
<xsl:output omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="messages">
<xsl:for-each select="note">
<xsl:call-template name="value-of-template">
<xsl:with-param name="select" select="from"/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template name="value-of-template">
<xsl:param name="select"/>
<xsl:value-of select="$select"/>
<xsl:for-each select="exslt:node-set($select)[position()&gt;1]">
<xsl:value-of select="'&#10;'"/>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment