RE: [xsl] preceding-sibling:: while keeping xml well formed

Subject: RE: [xsl] preceding-sibling:: while keeping xml well formed
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 31 May 2005 18:20:37 +0100
Try something like:

<xsl:template match="b//i | i//b">
  <bolditalic>
    <xsl:apply-templates/>
  </bolditalic>
</xsl:template>

In your example the b is an ancestor or descendant of the i, not a sibling.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Spencer Tickner [mailto:spencertickner@xxxxxxxxx] 
> Sent: 31 May 2005 17:48
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] preceding-sibling:: while keeping xml well formed
> 
> Hello, and thanks in advance for the help.
> 
> I am using xslt to convert one xml to another importable xml.
> Everything is going fine except for the fact that the program I am
> importing into supports <italic>, and <bold>, but needs a <bolditalic>
> when the both are together.
> 
> My original xml file is used on the web so of course 
> 
> <i>This<b>is</b>valid</i>.
> 
> I assume this can be done using the preceding-sibiling axis to achive
> something along the lines of
> 
> <italic>This</italic><bolditalic>is</boldItalic><italic>valid</italic>
> 
> So far I'm just hitting templates with my inline elements, However I
> still just get <bold> and <italic> tags with the xsl below:
> 
> 
> XML
> 
> <document>
>   <test>This <b>is a <i>test</i> of bolditalic</b> type</test>
> </document>
> 
> XSLT
> 
> <xsl:template match="document">
> 	<xsl:apply-templates select="test"/>
> </xsl:template>
> 
> <xsl:template match="test">
> 	<xsl:element name="newxmltag">
> 		<xsl:applytemplates="text()|i|b"/>
> 	</xsl:element>
> </xsl:template>
> 
> <xsl:template match="b">
> <xsl:choose>
> 	<xsl:when test="preceding-sibling::strong">
> 		<xsl:element name="bolditalic">
> 			<xsl:apply-templates/>
> 		</xsl:element>
> 	</xsl:when>
>         <xsl:otherwise>
> 		<xsl:element name="bold">
> 			<xsl:apply-templates/>
> 		</xsl:element>
> 	</xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> 
> <xsl:template match="i">
> <xsl:choose>
> 	<xsl:when test="preceding-sibling::strong">
> 		<xsl:element name="bolditalic">
> 			<xsl:apply-templates/>
> 		</xsl:element>
> 	</xsl:when>
> 	<xsl:otherwise>
> 		<xsl:element name="italic">
> 			<xsl:apply-templates/>
> 		</xsl:element>
> 	</xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> 
> 
> 
> Any Help you all can offer would be very appreciated.
> 
> Thank you,
> 
> Spencer

Current Thread