-3
我需要使用XSLT 2.0将HTML文件转换为XML格式。该HTML文件仅包含<p>
标签,其类别为h1,h2,h3,...。 。 。使用XSLT 2.0进行HTML到XML转换
<body>
<p class='h1'>the fisr A</p>
<p class='txt'>one</p>
<p>tow</p>
<p class='h2'>the sec B</p>
<p class='txt'>theree</p>
<p class='h2'>the sec sec B</p>
<p class='txt'>the next text</p>
<p class='h3'>the fisr C</p>
<p class='txt'>four</p>
<p class='txt'>five</p>
<p class='h1'>the seccond A</p>
<p class='txt'>the seccond txt</p>
<p class='h2'>the second B</p>
<p class='txt'>six</p>
<p class='txt'>seven</p>
<p class='h1'>the third A</p>
<p class='txt'>eight</p>
<p class='txt'>nine</p>
</body>
我需要的XML输出如下图所示
<book>
<sectionA>
<title>the fisr A</title>
<p class="txt">one</p>
<p>tow</p>
<sectionB>
<title>the sec B</title>
<p class="txt">theree</p>
</sectionB>
<sectionB>
<title>the sec sec B</title>
<p class="txt">the next text</p>
<sectionC>
<title>the fisr C</title>
<p class="txt">four</p>
<p class="txt">five</p>
</sectionC>
</sectionB>
</sectionA>
<sectionA>
<title>the seccond A</title>
<p class="txt">the seccond txt</p>
<sectionB>
<title>the second B</title>
<p class="txt">six</p>
<p class="txt">seven</p>
</sectionB>
</sectionA>
<sectionA>
<title>the third A</title>
<p class="txt">eight</p>
<p class="txt">nine</p>
</sectionA>
</book>
谁能帮我得到所需的输出?
看一看的第三个例子在这里:https://www.w3.org/TR/xslt20/#grouping-examples –
与为它去'的'并实现你的逻辑。这种苛刻的评论是因为你缺乏“自己尝试”和“让社区为我编写代码”。 SO是为了帮助,而不是为了编码请求。 –
uL1
我尝试使用for-each-group,但无法提供预期的输出 – Reegan