Transform XML structure using XSLT -
i want transform xml structure xslt.
<detaileddescription> <para>some text</para> <para> <bold>title</bold> </para> <para>intro text: <itemizedlist> <listitem> <para>text</para> </listitem> <listitem> <para>text</para> </listitem> </itemizedlist> </para> </detaileddescription>
this want:
<detaileddescription> <para>some text</para> <list> <title>title</title> <intro> intro text: </intro <listitem> <para>text</para> </listitem> <listitem> <para>text</para> </listitem> </list> </detaileddescription>
so in own words: if there <bold>
inside <para>
, check if following-sibling of <para>
<para>
, has child <para>text</para>
want rebuild structure shown.
i'm not sure if possible, because have started using xslt/xpath. can give me little help?
if want use conditions on nodes suggest put them match patterns:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="detaileddescription/para[bold][following-sibling::*[1][self::para[.//para]]]"> <list> <title> <xsl:value-of select="bold"/> </title> <xsl:apply-templates select="following-sibling::*[1]" mode="intro-list"/> </list> </xsl:template> <xsl:template match="detaileddescription/para[.//para][preceding-sibling::*[1][self::para[bold]]]"/> <xsl:template match="detaileddescription/para/text()[1]" mode="intro-list"> <intro> <xsl:value-of select="."/> </intro> </xsl:template> <xsl:template match="listitem" mode="intro-list"> <listitem> <xsl:apply-templates/> </listitem> </xsl:template> </xsl:transform>
see http://xsltransform.net/3nzcbtk/2 sample.
Comments
Post a Comment