Skip to content

Instantly share code, notes, and snippets.

@dericed
Created January 23, 2012 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dericed/1665773 to your computer and use it in GitHub Desktop.
Save dericed/1665773 to your computer and use it in GitHub Desktop.
xsl to translate filemaker output to dublist.xml
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="fmp xsl">
<xsl:output encoding="UTF-8" method="xml" version="1.0" indent="yes"/>
<xsl:key name="N" match="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD" use="@NAME"/>
<xsl:key name="N" match="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD" use="following-sibling::fmp:FIELD/@NAME"/>
<xsl:template match="fmp:FMPXMLRESULT">
<xsl:apply-templates select="fmp:RESULTSET"/>
</xsl:template>
<xsl:template match="fmp:FMPXMLRESULT/fmp:RESULTSET">
<PBSDubList>
<DubItems>
<xsl:for-each select="fmp:ROW">
<xsl:variable name="row_pos" select="position()"/>
<xsl:variable name="asset_pk"><xsl:value-of select="fmp:COL[count(key('N','asset_serial_pk'))]/fmp:DATA"/></xsl:variable>
<DubItem>
<xsl:for-each select="fmp:COL[count(key('N', 'device_id'))]/fmp:DATA">
<xsl:variable name="pos" select="position()"/>
<TapeId>
<xsl:value-of select="../../fmp:COL[count(key('N','device_id'))]/fmp:DATA[$pos]"/>
</TapeId>
</xsl:for-each>
<xsl:for-each select="fmp:COL[count(key('N', 'material_id'))]/fmp:DATA">
<xsl:variable name="pos" select="position()"/>
<MediaId>
<xsl:value-of select="../../fmp:COL[count(key('N','material_id'))]/fmp:DATA[$pos]"/>
</MediaId>
</xsl:for-each>
<xsl:for-each select="fmp:COL[count(key('N', 'timecode_in'))]/fmp:DATA">
<xsl:variable name="pos" select="position()"/>
<SOM>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','timecode_in'))]/fmp:DATA[$pos],1,2)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','timecode_in'))]/fmp:DATA[$pos],4,2)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','timecode_in'))]/fmp:DATA[$pos],7,2)"/>
<xsl:text>;</xsl:text>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','timecode_in'))]/fmp:DATA[$pos],10,2)"/>
</SOM>
</xsl:for-each>
<xsl:for-each select="fmp:COL[count(key('N', 'duration'))]/fmp:DATA">
<xsl:variable name="pos" select="position()"/>
<Duration>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','duration'))]/fmp:DATA[$pos],1,2)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','duration'))]/fmp:DATA[$pos],4,2)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','duration'))]/fmp:DATA[$pos],7,2)"/>
<xsl:text>;</xsl:text>
<xsl:value-of select="substring(../../fmp:COL[count(key('N','duration'))]/fmp:DATA[$pos],10,2)"/>
</Duration>
</xsl:for-each>
<xsl:for-each select="fmp:COL[count(key('N', 'PBCoreTitle_via_xml::title'))]/fmp:DATA">
<xsl:variable name="pos" select="position()"/>
<Title>
<xsl:value-of select="../../fmp:COL[count(key('N','PBCoreTitle_via_xml::title'))]/fmp:DATA[$pos]"/>
</Title>
</xsl:for-each>
<xsl:for-each select="fmp:COL[count(key('N', 'PBCoreDescription_via_xml::description'))]/fmp:DATA">
<xsl:variable name="pos" select="position()"/>
<Notes>
<xsl:value-of select="../../fmp:COL[count(key('N','PBCoreDescription_via_xml::description'))]/fmp:DATA[$pos]"/>
</Notes>
</xsl:for-each>
</DubItem>
</xsl:for-each>
</DubItems>
</PBSDubList>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment