<p>
タグ内のタグはすべて<body>
に変換する必要がありますBody_Text
。属性""のない最後
<p>
の祖先を持つタグは、に変換する必要があります(これはここでの最初の変換をオーバーライドします)。<sec>
sec-type
Flush_Text
Body_Text
<p>
最後の祖先(属性 "")を持つタグは<sec sec-type="irrelevant-attribute-name>
に変換するsec-type
必要がありますBody_Text
。
<sec><p>asdf</p></sec>
に変換する必要があります<sec><Flush_Text>asdf</Flush_Text></sec>
。
<sec sec-type="whatevs"><p>asdf</p></sec>
である必要があります<sec sec-type="whatevs"><Body_Text>asdf</Body_Text></sec>
。
また
sec-type
、この属性を使用して祖先にさらにネストする場合は、Body_Text
:
<sec sec-type="whatevs"><sec><p>asdf</p></sec></sec>
である必要があります<sec sec-type="whatevs"><sec><Body_Text>asdf</Body_Text></sec>
。
これが私のXMLです:
<root>
<body>
<sec sec-type="asdf">
<title>This is an H1</title>
<sec>
<title>This is an H2</title>
<sec>
<title>This is an H3</title>
<p>This SHOULD be "Body_Text", but it's "Flush_Text"</p>
</sec> <!-- end of H3 -->
</sec> <!-- end of H2 -->
</sec> <!-- end of H1 -->
<sec>
<p>This is Flush_Text</p>
</sec>
<p>This is Body_Text</p>
</body>
</root>
...これが私のXSLですが、正しく機能して
いません:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<!-- identity rule -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- Body_Text -->
<xsl:template match="body//p">
<Body_Text>
<xsl:apply-templates select="@*|node()"/>
</Body_Text>
</xsl:template>
<!-- Flush_Text -->
<xsl:template match="sec//p">
<xsl:if test="not(@sec-type)">
<Flush_Text>
<xsl:apply-templates select="@*|node()"/>
</Flush_Text>
</xsl:if>
</xsl:template>
<!-- H1 -->
<xsl:template match="sec//title">
<H1>
<xsl:apply-templates select="@*|node()"/>
</H1>
</xsl:template>
<!-- H2 -->
<xsl:template match="sec//sec//title">
<H2>
<xsl:apply-templates select="@*|node()"/>
</H2>
</xsl:template>
<!-- H3 -->
<xsl:template match="sec//sec//sec//title">
<H3>
<xsl:apply-templates select="@*|node()"/>
</H3>
</xsl:template>
</xsl:stylesheet>
...そしてここに間違った出力があります:
<?xml version="1.0" encoding="utf-16"?>
<root>
<body>
<sec sec-type="asdf">
<H1>This is an H1</H1>
<sec>
<H2>This is an H2</H2>
<sec>
<H3>This is an H3</H3>
<Flush_Text>This SHOULD be "Body_Text", but it's "Flush_Text"</Flush_Text>
</sec>
<!-- end of H3 -->
</sec>
<!-- end of H2 -->
</sec>
<!-- end of H1 -->
<sec>
<Flush_Text>This is Flush_Text</Flush_Text>
</sec>
<Body_Text>This is Body_Text</Body_Text>
</body>
</root>
<p>
この例の最初のインスタンスはに変換する必要がありますBody_Text
が、として変換されていることに注意してくださいFlush_Text
。