Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2017 12:26
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 anonymous/d31514f67f11725706dea2ff5085a721 to your computer and use it in GitHub Desktop.
Save anonymous/d31514f67f11725706dea2ff5085a721 to your computer and use it in GitHub Desktop.
<data>
<hello>paste your xml here</hello>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
ion="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:template match="/root">
<root>
<xsl:for-each select="item">
<xsl:if test="@znam_avg!=999999">
<td>
<xsl:value-of select="@val_avg" />
<xsl:if test="@flag_minus=-1">
<xsl:value-of select="'(-1/'" />
<xsl:call-template name="left-trim">
<xsl:with-param name="string" select="@znam_avg" />
</xsl:call-template>
<xsl:value-of select="')'" />
</xsl:if>
<xsl:if test="@flag_minus=1">
<xsl:value-of select="'(1/'" />
<xsl:call-template name="left-trim">
<xsl:with-param name="string" select="@znam_avg" />
</xsl:call-template>
<xsl:value-of select="')'" />
</xsl:if>
</td>
</xsl:if>
</xsl:for-each>
</root>
</xsl:template>
<!-- trim-left recursive template -->
<xsl:template name="left-trim">
<xsl:param name="string" select="''" />
<xsl:variable name="tmp" select="substring($string, 1, 1)" />
<xsl:choose>
<xsl:when test="$tmp = ' ' or $tmp = '&#xA;'">
<xsl:call-template name="left-trim">
<xsl:with-param name="string" select="substring-after($string, $tmp)" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment