Ich möchte die Topic-Elemente mit dem XSL bestellen. Ich habe viel Segment, das alle Segmente, die ich als separates Thema genommen hatte. Jetzt möchte ich die verschiedenen Eingabe bekommen, so möchte ich, wie sich ändern untenMüssen die Topic-Ausrichtung ändern
Meine Eingangs XML ist:
<Segments>
<Segment>
<Name>Food poisoning?</Name>
<Body>
<p>Food</p>
</Body>
</Segment>
<Segment>
<Name>Causes food poisoning?</Name>
<Body>
<p>Most</p>
<h3>Salmonella</h3>
<p>most</p>
</Body>
</Segment>
</Segments>
XSL ich als:
<xsl:template match="Segments">
<xsl:for-each-group select="*" group-starting-with="Segments">
<topic outputclass="">
<xsl:attribute name="id">topic_Head_<xsl:number count="Segments | Segment"/></xsl:attribute>
<title/>
<xsl:for-each-group select="current-group()" group-starting-with="Segment">
<xsl:choose>
<xsl:when test="self::Segment">
<topic>
<xsl:attribute name="id">topic_<xsl:number count="Segment"/></xsl:attribute>
<xsl:apply-templates select="node()"/>
</topic>
</xsl:when>
<xsl:otherwise>
<body><xsl:apply-templates select="current-group()"/></body>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</topic>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="Name">
<title><xsl:apply-templates/></title>
</xsl:template>
<xsl:template match="p">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="h3">
</xsl:template>
<xsl:template match="Body">
<body>
<xsl:apply-templates/>
</body>
</xsl:template>
Output Ich erhalte als:
<topic outputclass="" id="topic_Head_1">
<title/>
<topic id="topic_1">
<title>Food poisoning?</title>
<body>
<p>Food</p>
</body>
</topic>
<topic id="topic_2">
<title>Causes food poisoning?</title>
<body>
<p>Most</p>
<p>most</p>
</body>
</topic>
</topic>
Erwartete Ausgabe wie:
<topic outputclass="" id="topic_Head_1">
<title/>
<topic id="topic_1">
<title>Food poisoning?</title>
<body>
<p>Food</p>
</body>
</topic>
<topic id="topic_2">
<title>Causes food poisoning?</title>
<body>
<p>Most</p>
</body>
<topic id="topic_3">
<title>Salmonella</title>
<body>
<p>most</p>
</body>
</topic>
</topic>
</topic>
Ich brauche das h3-Tag muss wie ein anderes Unterthema innerhalb des Segments kommen. Bitte geben Sie Ihre Vorschläge an. Vielen Dank im Voraus
Es funktioniert gut @Lesiak. Aber für den ersten h3 Titel havingh der Para-Inhalt wie am meisten . Anders als für die restlichen h3 Tiltes funktionieren gut. Bitte überprüfen Sie –
User501
Bitte überprüfen Sie diese XSL Transform Link http://xsltransform.net/94AbWAY/1 – User501
Aktualisierte Antwort mit "h3 [1] | h3 [1]/folgende Geschwister :: *" (hinzugefügt h3 [1]) in thew vorherige Antwort Ich bearbeitete vorhergehende und folgende Geschwister, und vermied das h3 elem. Du könntest dir vorstellen, dass du einfach so etwas wie: * [nicht (h3 [1]/folgendes Geschwister :: *)] – Lesiak