Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Not sure where else to put this
- <!-- siunitx templates
- this one is called when the u attribute
- is not used, e.g
- <quant n="1/5"/>
- becomes
- \num{1/5}
- <xsl:template match="quant[not(@u)]">
- <xsl:choose>
- <xsl:when test="@n">
- <xsl:text>\num{</xsl:text>
- <xsl:value-of select="@n"/>
- <xsl:text>}</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>??quantity fix??</xsl:text>
- <xsl:message terminate="no">
- <xsl:text>no 'n' attribute present (no units either)</xsl:text>
- </xsl:message>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- -->
- <!-- siunitx commands when the u attribute is used,
- e.g
- <quant u="kilo;gram;meter;" />
- <quant u="kilo:1;gram:2;meter:3;" />
- <quant n="63" u="kilo:1;gram:2;meter:3;" />
- <quant n="63" u="kilo:1;gram:2;meter:3;" per="liter:4" />
- becomes
- \si{\kilo\gram\meter}
- \si{\kilo\tothe{1}\gram\tothe{2}\meter\tothe{3}}
- \SI{63}{\kilo\tothe{1}\gram\tothe{2}\meter\tothe{3}}
- \SI{63}{\kilo\tothe{1}\gram\tothe{2}\meter\tothe{3}\per\liter\tothe{4}}
- -->
- <xsl:template match="quant[@u]">
- <xsl:param name="unitText" select="@u"/>
- <xsl:choose>
- <!-- quantity with number -->
- <xsl:when test="@n">
- <xsl:text>\SI{</xsl:text>
- <xsl:value-of select="@n"/>
- <xsl:text>}{</xsl:text>
- </xsl:when>
- <!-- quantity with*out* number -->
- <xsl:otherwise>
- <xsl:text>\si{</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <!-- either way, split the units and put them in -->
- <xsl:call-template name="split">
- <xsl:with-param name="unitText" select="$unitText"/>
- </xsl:call-template>
- <!-- if the per attribute exists, then apply it -->
- <xsl:if test="@per">
- <xsl:text>\per</xsl:text>
- <xsl:call-template name="split">
- <xsl:with-param name="unitText" select="@per"/>
- </xsl:call-template>
- </xsl:if>
- <xsl:text>}</xsl:text>
- </xsl:template>
- <!-- template to split the units at the semi-colon, and then
- at the colon -->
- <xsl:template name="split">
- <xsl:param name="unitText"/>
- <xsl:if test="string-length($unitText)">
- <!-- split string at semi-colon
- http://stackoverflow.com/questions/4845660/xsl-how-to-split-strings -->
- <xsl:variable name="eachUnit">
- <xsl:value-of select="substring-before(concat($unitText,';'),';')"/>
- </xsl:variable>
- <!-- test if the string contains a :
- http://stackoverflow.com/questions/569908/is-there-an-xsl-contains-directive -->
- <xsl:choose>
- <!-- split each unit at the colon : (to get the exponent)
- but only when there is one -->
- <xsl:when test="contains($eachUnit,':')">
- <!-- insert the backslash -->
- <xsl:text>\</xsl:text>
- <xsl:value-of select="substring-before($eachUnit,':')"/>
- <xsl:text>\tothe{</xsl:text>
- <xsl:value-of select="substring-after($eachUnit,':')"/>
- <xsl:text>}</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <!-- insert the backslash -->
- <xsl:text>\</xsl:text>
- <xsl:value-of select="substring-before($unitText,';')"/>
- </xsl:otherwise>
- </xsl:choose>
- <!-- call this template recursively -->
- <xsl:call-template name="split">
- <xsl:with-param name="unitText" select="substring-after($unitText, ';')"/>
- </xsl:call-template>
- </xsl:if>
- </xsl:template>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement