Reputation: 117
I want to format the number and rearrange the child nodes about the same format.
This is XML:
<?xml version="1.0" encoding="utf-8"?>
<include>
...
<data>
<id>10001</id>
<name>Archery classroom</name>
<level>0</level>
<description_5>Primary archery class.</description_5>
<maxLevel>8</maxLevel>
<skillRank>1</skillRank>
<coolDownTime>6000</coolDownTime>
<needMoney>5980</needMoney>
<needSkillPoint>2</needSkillPoint>
<skillUnitDataID>10001</skillUnitDataID>
<icon>28</icon>
<description_2>3</description_2>
<coolDownID>10001</coolDownID>
</data>
<data>
<id>10002</id>
<name>Archery classroom</name>
<level>1</level>
<maxLevel>8</maxLevel>
<skillRank>1</skillRank>
<coolDownID>10002</coolDownID>
<skillUnitDataID>10002</skillUnitDataID>
<needMoney>15980</needMoney>
<needSkillPoint>2</needSkillPoint>
<coolDownTime>16000</coolDownTime>
<icon>28</icon>
<description_2>3</description_2>
<description_3>11</description_3>
<description_5>Primary archery class.</description_5>
</data>
...
</include>
I want to separate the group for thousands for coolDownTime
and rearrange the child nodes according to the same order: id
-> name
-> level
-> maxLevel
-> skillRank
-> needMoney
-> needSkillPoint
-> coolDownID
-> coolDownTime
-> skillUnitDataID
-> description_1
-> description_2
-> description_3
-> description_4
-> description_5
-> icon
.
This is the XSL code I used to do this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:output indent="yes" omit-xml-declaration="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="data">
<xsl:copy>
<xsl:apply-templates select="id|name|level|maxLevel|skillRank|needMoney|needSkillPoint|coolDownID"/>
<coolDownTime>
<xsl:value-of select="format-number(coolDownTime,'#,000.#######')"/>
</coolDownTime>
<xsl:apply-templates select="skillUnitDataID|description_1|description_2|description_3|description_4|description_5|icon"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But the results I received only coolDownTime
were formatted group separation for thousands, the child nodes didn't arrange in the order that I was predetermined.
It seems that the code I wrote wasn't exactly somewhere.
So I'm very pleased with the suggestions you give.
Upvotes: 0
Views: 45
Reputation: 167571
Use the "comma operator" ,
to select items in a certain order (e.g. id, name, level
), not the union operators |
which forms sequences of nodes sorted in document order.
Upvotes: 1