Skip to content

Instantly share code, notes, and snippets.

@tts
Created March 6, 2013 12:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tts/5099042 to your computer and use it in GitHub Desktop.
Save tts/5099042 to your computer and use it in GitHub Desktop.
Anonymize GEXF node labels
<!--
Transform (anonymize) node labels in a GEXF file
Tuija Sonkkila 6.3.2013
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:g="http://www.gexf.net/1.2draft"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="g:node[@label]">
<!-- Make initials out of fullnames -->
<xsl:variable name="initials" select="replace(@label, '^(.)[^\s]+\s*(.).*$', '$1$2')"/>
<xsl:copy>
<xsl:attribute name="label">
<xsl:value-of select="$initials"/>
</xsl:attribute>
<xsl:copy-of select="@* except @label"/>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment