Estoy intentando escribir XSLT que ejecutará un for-each en los hermanos siguientes seleccionados pero se detendrá cuando se alcance otra etiqueta (h1).XSLT: Seleccione siguiente hermano hasta alcanzar una etiqueta específica
Aquí está el origen de XML:
<?xml version="1.0"?>
<html>
<h1>Test</h1>
<p>Test: p 1</p>
<p>Test: p 2</p>
<h1>Test 2</h1>
<p>Test2: p 1</p>
<p>Test2: p 2</p>
<p>Test2: p 3</p>
</html>
aquí está el XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<content>
<xsl:apply-templates/>
</content>
</xsl:template>
<xsl:template match="h1">
<section>
<sectionHeading>
<xsl:apply-templates/>
</sectionHeading>
<sectionContent>
<xsl:for-each select="following-sibling::p">
<paragraph>
<xsl:value-of select="."/>
</paragraph>
</xsl:for-each>
</sectionContent>
</section>
</xsl:template>
<xsl:template match="p"/>
</xsl:stylesheet>
Aquí está el resultado actual:
<?xml version="1.0" encoding="UTF-8"?>
<content>
<section>
<sectionHeading>Test</sectionHeading>
<sectionContent>
<paragraph>Test: p 1</paragraph>
<paragraph>Test: p 2</paragraph>
<paragraph>Test: p 3</paragraph>
<paragraph>Test2: p 1</paragraph>
<paragraph>Test2: p 2</paragraph>
</sectionContent>
</section>
<section>
<sectionHeading>Test 2</sectionHeading>
<sectionContent>
<paragraph>Test2: p 1</paragraph>
<paragraph>Test2: p 2</paragraph>
</sectionContent>
</section>
</content>
Aquí está el resultado esperado:
<?xml version="1.0" encoding="UTF-8"?>
<content>
<section>
<sectionHeading>Test</sectionHeading>
<sectionContent>
<paragraph>Test: p 1</paragraph>
<paragraph>Test: p 2</paragraph>
<paragraph>Test: p 3</paragraph>
</sectionContent>
</section>
<section>
<sectionHeading>Test 2</sectionHeading>
<sectionContent>
<paragraph>Test2: p 1</paragraph>
<paragraph>Test2: p 2</paragraph>
</sectionContent>
</section>
</content>
@ Tim, aunque podemos obtener una solución para XSLT yo preferiría sugerir que cambie el formato XML para Lo que tiene más sentido y es legible, también es fácil de consultar en xslt. –
Ravisha
prueba
prueba: p 1
prueba: p 2
Prueba 2
Test2: p 1
Test2: p 2
Test2: p 3