1
私は数時間XSLTに苦労していて、私はStackOverflowに助けを求めました。私は、これが驚くほど難しいことではありません知っているが、私はそれを得ることはありません... XSLTをこのいくつかのXML要素をXSLTでグループ化する
<?xml version="1.0" encoding="UTF-8"?>
<div>
<p>Some regular text</p>
<group>
<p>The first part</p>
<p>and then some text</p>
<p>and some more</p>
</group>
<p>Some regular text</p>
<p>Some regular text</p>
<p>Some regular text</p>
<group>
<p>Here some new text</p>
<p>and some more</p>
<p>and the end of this section</p>
</group>
<p>Some regular text</p>
</div>
で終わるしたい
<?xml version="1.0" encoding="UTF-8"?>
<div>
<p class="text">Some regular text</p>
<p class="first">The first part</p>
<p class="next">and then some text</p>
<p class="next">and some more</p>
<p class="regular">Some regular text</p>
<p class="text1">Some regular text</p>
<p class="text2">Some regular text</p>
<p class="first">Here some new text</p>
<p class="next">and some more</p>
<p class="next">and the end of this section</p>
<p class="text3">Some regular text</p>
</div>
:私はこのようないくつかの入力テキストを持っています私は今持っている:誰も私を助けることができる場合、私は本当にXSLTがどのように機能するかを理解する問題を抱えているので、私は、非常に感謝される:(まったく動作しない
<?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:template match="/">
<xsl:apply-templates select="*" />
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy />
</xsl:for-each>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="div">
<lg>
<xsl:apply-templates/>
</lg>
</xsl:template>
<xsl:template match="/div">
<xsl:for-each-group select="//p[@class='first']/following-sibling::p[@class='next']" group-by="text()">
<group>
<xsl:apply-templates/>
</group>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
...
敬具、 ホセ・
こんにちはティム、感謝をしてみてください!!私が理解している限り、あなたはこのpを否定的な方法で定義することを選択しています。pはクラスを持たないものです。私たちはそれを積極的に試すことができますか?その特定のクラスの要素を選択しますか?私はこのように驚きを入れたら、うまくいきませんでした。 –
xml入力を編集してそれをより良くカバーしました。 –
私は2つの可能なXSLTで答えを更新しました。 –