必要なxml要素をブロックで取得しますが、同時に、他のxml要素をキャッチするためのブロックも配置します.しかし、それは私にとってはうまくいきません...
これは XML ドキュメントです
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:pPr>
</w:pPr>
<w:r>
<w:t>Text1-</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1" />
</w:pPr>
<w:r>
<w:t>Text2-</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
</w:pPr>
<w:r>
<w:t>Text3-</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
</w:pPr>
<w:r>
<w:t>Text4-</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1" />
</w:pPr>
<w:r>
<w:t>Text5-</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
これは XSLT ファイルです
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
exclude-result-prefixes="w">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<Document>
<xsl:variable name="headingName" select="(//w:body/w:p/w:pPr/w:pStyle[starts-with(@w:val, 'Heading')])[1]/@w:val"/>
<xsl:variable name="topLevelHeadings" select = "//w:body/w:p[w:pPr/w:pStyle/@w:val = $headingName]"/>
<xsl:choose>
<xsl:when test="$topLevelHeadings">
<Heading>
<xsl:apply-templates select="$topLevelHeadings">
</xsl:apply-templates>
</Heading>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="w:p">
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</Document>
</xsl:template>
<xsl:template match="w:p">
<Paragraph>
<xsl:apply-templates />
</Paragraph>
</xsl:template>
<xsl:template match="w:r/w:t">
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
私の生成された出力は次のとおりです。
<Document>
<Heading>
<Paragraph>Text2-</Paragraph>
<Paragraph>Text5-</Paragraph>
</Heading>
</Document>
しかし、私の必要な出力は次のとおりです。
<Document>
<Paragraph>Text1-</Paragraph>
<Heading>
<Paragraph>Text2-</Paragraph>
</Heading>
<Paragraph>Text3-</Paragraph>
<Paragraph>Text4-</Paragraph>
<Heading>
<Paragraph>Text5-</Paragraph>
</Heading>
</Document>
Block に問題があると思います。だから、この問題から抜け出すために私を導いてください...