Mon code XML d'entrée: sortie réelle: p> sortie attendue: p> <xsl:template match="content/body//pre|em">
<xsl:choose>
<xsl:when test="pre">
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise>
<div>
<xsl:apply-templates />
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="content/body/pre/em/pre">
<xsl:apply-templates select="./node()" />
</xsl:template>
4 Réponses :
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="h2"/>
<xsl:template match="pre|em">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="title">
<xsl:choose>
<xsl:when test=" not(preceding::title)">
<div>
<title>
<xsl:value-of select="."/>
</title>
</div>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::h2]">
<div>
<xsl:copy-of select="preceding-sibling::*[1][self::h2]"/>
<title><xsl:value-of select="."/></title>
</div>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="h1">
<div>
<h1><xsl:value-of select="."/></h1>
</div>
</xsl:template>
<xsl:template match="li">
<div>
<li><xsl:value-of select="."/></li>
</div>
</xsl:template>
Try it.
Les étiquettes d'enfants ne sont pas statiques ..may ils sont âgés de 4 ou 5 peuvent être une seule étiquette enfant..so Nous ne pouvons pas appliquer les règles particulières pour LI, H1. Alors le code devrait être dynamique
Vous pouvez donner votre fichier d'entrée complet.
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="title">
<xsl:choose>
<xsl:when test=" not(preceding::title)">
<div>
<title>
<xsl:value-of select="."/>
</title>
</div>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::h2]">
<div>
<xsl:copy-of select="preceding-sibling::*[1][self::h2]"/>
<title><xsl:value-of select="."/></title>
</div>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="h1|li">
<div>
<xsl:copy-of select="."/>
</div>
</xsl:template>
<xsl:template match="pre|em">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="h2"/>
Vous pouvez y parvenir via des modèles d'application aux nœuds cibles le voir en action ici . p> p>
Ceci est un Grouper problème. Dans XSLT 2.0, vous pouvez utiliser cette transformation et cette entrée p> résultat p>