gpt4 book ai didi

.net - 通缉 : xsl:template that converts a node to its hexavigesimal value?

转载 作者:行者123 更新时间:2023-12-01 05:31:44 25 4
gpt4 key购买 nike

我几乎可以在这里说:“@##$# 是什么 hexavigesimal 值?”

A hexavigesimal numeral system has a base of twenty-six. Alternatively, base-26 may be represented using only letters of the Latin alphabet. As there are 26 letters in English, base-26 is also the highest base in which this is possible and hence utilizes every letter. 0 is represented by A, 1 = B, 2 = C ... 24 = Y, 25 = Z. Some examples: 26 = AA, 30 = BE



所以它基本上就是 Excel 使用的列描述。我想要一个函数,可以将具有 int 值的节点转换为该值。

来源:
<root>
<row>12</row>
<column>23</column>
</root>

我要打印 columnX通过调用进行转换的模板。可以做到吗?

最佳答案

试试这个 XSLT...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:variable name="symbols" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:variable name="symbols-count" select="string-length($symbols)" />
<xsl:template match="row">
<row>
<xsl:call-template name="convert" />
</row>
</xsl:template>

<xsl:template name="convert">
<xsl:param name="value" select="number(.)" />
<xsl:choose>
<xsl:when test="$value >= $symbols-count">
<xsl:variable name="div" select="floor($value div $symbols-count)" />
<xsl:variable name="remainder" select="$value - $div * $symbols-count" />
<xsl:call-template name="convert">
<xsl:with-param name="value" select="$div" />
</xsl:call-template>
<xsl:value-of select="substring($symbols, $remainder + 1, 1)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($symbols, $value + 1, 1)" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

应用于以下 XML 时
<root>
<row>12</row>
<column>23</column>
<row>26</row>
<column>23</column>
</root>

以下是输出
<root>
<row>M</row>
<column>23</column>
<row>BA</row>
<column>23</column>
</root>

您应该能够调整 符号 变量以允许任何花式命名的 imal 转换。例如,要转换为十六进制将其更改为以下内容
<xsl:variable name="symbols" select="'0123456789ABCDEF'" />

和二进制
<xsl:variable name="symbols" select="'01'" />

关于.net - 通缉 : xsl:template that converts a node to its hexavigesimal value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10751983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com