明白な答え - 10 を掛けるか、または a で連結すること'0'
は既に提案されました。
より一般的な解決策は次のとおりです。
この変換は、 8 未満の任意の値の最後にlatitude
、必要なゼロの正確な数を追加します。longitude
string-length()
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="
*[self::latitude or self::longitude
and
not(string-length() >= 8)
or
(starts-with(., '-') and not(string-length() >= 9))
]">
<xsl:copy>
<xsl:value-of select=
"concat(.,
substring('00000000',
1,
8 + starts-with(., '-') - string-length())
)
"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
この XML ドキュメントに適用すると:
<coordinates>
<latitude>3876570</latitude>
<longitude>-9013376</longitude>
</coordinates>
必要な正しい結果が生成されます。
<coordinates>
<latitude>38765700</latitude>
<longitude>-90133760</longitude>
</coordinates>
この XML ドキュメントに適用した場合:
<coordinates>
<latitude>123</latitude>
<longitude>-99</longitude>
</coordinates>
ここでも、必要な正しい結果が生成されます。
<coordinates>
<latitude>12300000</latitude>
<longitude>-99000000</longitude>
</coordinates>
注意してください:
式では:
substring('00000000',
1,
8 + starts-with(., '-') - string-length())
ブール値が算術演算子の引数である場合は常に、次の規則を使用して数値に変換されるという事実を使用します。
number(true()) = 1
と
number(false()) = 0
したがって、上記の式は、現在のノードの値が負の場合にもう 1 つゼロを抽出します。これは、マイナス記号を考慮して、数値に追加する必要があるゼロの正確な数を取得するためです。