Skip to content

Instantly share code, notes, and snippets.

@thatseeyou
Created December 1, 2016 16:25
Show Gist options
  • Save thatseeyou/e65e80cfbc5e76075aabce787f7667cd to your computer and use it in GitHub Desktop.
Save thatseeyou/e65e80cfbc5e76075aabce787f7667cd to your computer and use it in GitHub Desktop.
XSLT: XML to space delimited file
<?xml version='1.0' encoding='UTF-8'?>
<!-- filtered response of Picasa Web Albums Data API -->
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007'>
<entry>
<id>https://picasaweb.google.com/data/entry/user/117547036153868951227/albumid/6358821083271905537</id>
<published>2016-11-30T17:53:24.000Z</published>
<updated>2016-11-30T17:53:25.924Z</updated>
<link href='https://picasaweb.google.com/data/entry/api/user/117547036153868951227/albumid/6358821083271905537'/>
<gphoto:id>6358821083271905537</gphoto:id>
<gphoto:timestamp>1480528404000</gphoto:timestamp>
<gphoto:numphotos>0</gphoto:numphotos>
</entry>
<entry>
<id>https://picasaweb.google.com/data/entry/user/117547036153868951227/albumid/6358820656966241745</id>
<published>2016-11-30T17:51:45.000Z</published>
<updated>2016-11-30T17:51:46.271Z</updated>
<link href='https://picasaweb.google.com/data/entry/api/user/117547036153868951227/albumid/6358820656966241745'/>
<gphoto:id>6358820656966241745</gphoto:id>
<gphoto:timestamp>1480528305000</gphoto:timestamp>
<gphoto:numphotos>0</gphoto:numphotos>
</entry>
<entry>
<id>https://picasaweb.google.com/data/entry/user/117547036153868951227/albumid/6358819343315912465</id>
<published>2016-11-30T17:46:39.000Z</published>
<updated>2016-11-30T17:46:40.410Z</updated>
<link href='https://picasaweb.google.com/data/entry/api/user/117547036153868951227/albumid/6358819343315912465'/>
<gphoto:id>6358819343315912465</gphoto:id>
<gphoto:timestamp>1480527999000</gphoto:timestamp>
<gphoto:numphotos>0</gphoto:numphotos>
</entry>
</feed>
<?xml version="1.0" encoding="utf-8"?>
<!-- XML to space delimited file -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007'>
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/"><xsl:apply-templates select="/f:feed/f:entry"/></xsl:template>
<xsl:template match="f:entry">
<xsl:value-of select="./f:published"/><xsl:text> </xsl:text><xsl:value-of select="./gphoto:id"/>
<xsl:if test="position()!=last()">
<xsl:text>&#10;</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
$ xsltproc entries.xsl entries.xml
2016-11-30T17:53:24.000Z 6358821083271905537
2016-11-30T17:51:45.000Z 6358820656966241745
2016-11-30T17:46:39.000Z 6358819343315912465
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment