XML:
<t>
<ScreenSize>
<Width>1440</Width>
<Height>900</Height>
</ScreenSize>
<ConfigurationHotSpots>
<Rectangle>
<Location>
<X>0</X>
<Y>0</Y>
</Location>
<Size>
<Width>50</Width>
<Height>50</Height>
</Size>
<X>0</X>
<Y>0</Y>
<Width>50</Width>
<Height>50</Height>
</Rectangle>
</ConfigurationHotSpots>
</t>
必要な出力XML:
<t>
<ScreenSizeWidth>1440</ScreenSizeWidth>
<ScreenSizeWidth>900</ScreenSizeWidth>
<ConfigurationHotSpotsRectangleLocationX>0</ConfigurationHotSpotsRectangleLocationX>
<ConfigurationHotSpotsRectangleLocationY>0</ConfigurationHotSpotsRectangleLocationY>
<ConfigurationHotSpotsRectangleSizeWidth>50</ConfigurationHotSpotsRectangleSizeWidth>
<ConfigurationHotSpotsRectangleSizeHeight>50</ConfigurationHotSpotsRectangleSizeHeight>
<ConfigurationHotSpotsRectangleX>0</ConfigurationHotSpotsRectangleX>
<ConfigurationHotSpotsRectangleY>0</ConfigurationHotSpotsRectangleY>
<ConfigurationHotSpotsRectangleWidth>50</ConfigurationHotSpotsRectangleWidth>
<ConfigurationHotSpotsRectangleHeight>50</ConfigurationHotSpotsRectangleHeight>
</t>
ルール:
- 定義されたノードセット(この場合
<ScreenSize> | <ConfigurationHotSpots>
)のすべての要素について、次の手順を実行します。新しい要素が作成されるように、すべての葉の子孫(つまり、子のない子孫)を処理します。この新しい要素の名前は、現在のノードと子のない子孫の間のすべての要素を連結したものである必要があります。 - ドキュメント全体でこれらの「ブロック」の数は可変であるため、手動テンプレートはありません(つまり、の子孫のみ
<ScreenSize>
を処理するもの、の子孫のみを処理するもの<ConfigurationHotSpots>
など)。
私が現在持っているもの:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output omit-xml-declaration="no" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="ScreenSize|ConfigurationHotSpots">
<xsl:apply-templates select="descendant::*[not(*)]" mode="descendants" />
</xsl:template>
<xsl:template match="*" mode="descendants">
<xsl:element name="{concat(name(ancestor::*[not(self::t)]), name())}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
問題はそのname(ancestor::*[not(self::t)])
部分のようです。それは私が望んでいることをしていません(それらの要素の名前を魔法のように次々に出力します)。代わりに、これは私が得るものです:
<?xml version="1.0" encoding="UTF-8"?>
<t>
<ScreenSizeWidth>1440</ScreenSizeWidth>
<ScreenSizeHeight>900</ScreenSizeHeight>
<ConfigurationHotSpotsX>0</ConfigurationHotSpotsX>
<ConfigurationHotSpotsY>0</ConfigurationHotSpotsY>
<ConfigurationHotSpotsWidth>50</ConfigurationHotSpotsWidth>
<ConfigurationHotSpotsHeight>50</ConfigurationHotSpotsHeight>
<ConfigurationHotSpotsX>0</ConfigurationHotSpotsX>
<ConfigurationHotSpotsY>0</ConfigurationHotSpotsY>
<ConfigurationHotSpotsWidth>50</ConfigurationHotSpotsWidth>
<ConfigurationHotSpotsHeight>50</ConfigurationHotSpotsHeight>
</t>
前もって感謝します!