Create a gist now

Instantly share code, notes, and snippets.

anonymous /master.xml
Created Sep 22, 2017

What would you like to do?
<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