Created
March 6, 2013 12:42
-
-
Save tts/5099042 to your computer and use it in GitHub Desktop.
Anonymize GEXF node labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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