Jump to content

Is it possible to manipulate previous output?


Xaake

Recommended Posts

Hello!I have a hard time describing what I want to do so that search engines understands me, so I am sorry if this has been discussed before...What I want to do is the following:Simplified input file:

<p><ul>...</ul></p><p>blabla</p><ul>...</ul><p>blabla:</p><ul>...</ul>

Wanted output:

<paragraph><list ordered="false">...</list></paragraph><paragraph>blabla</paragraph><paragraph><list ordered="false">...</list></paragraph><paragraph>blabla:<list ordered="false">...</list></paragraph>

And to try to explain what it is I am doing. I am doing the following:

<xsl:template match="p">   <paragraph>	  <xsl:apply-templates/>   </paragraph></xsl:template><xsl:template match="ul">   <xsl:if test="not(parent::p)">	  <paragraph>		 <list ordered="false">			 <xsl:apply-templates/>		 </list>	  </paragraph>   </xsl:if>   <xsl:if test="parent::p">		 <list ordered="false">			<xsl:apply-templates/>		 </list>   </xsl:if></xsl:template>

This makes gives me the following output

<paragraph><list ordered="false">...</list></paragraph><paragraph>blabla</paragraph><paragraph><list ordered="false">...</list></paragraph><paragraph>blabla:</paragraph><paragraph><list ordered="false">...</list></paragraph>

So the thing I want to do in the <template match="ul"> is to first check if <ul> already has a <p> parent and if not:I want to check if the preciding <p> text() ends with ':' and in that case insert the <list> into the already generated sibling <paragraph>Is this possible or does xslt only allow for linear generation?Thankful for help/Rickard Haake

Link to comment
Share on other sites

For those of you having similar problems, this is how I solved the above problem: (Note that this does not have the check if the last character is ':' yet)

<xsl:template match="p">   <paragraph>	  <xsl:apply-templates/>	  	  <xsl:if test="name(following-sibling::*)='ul'">		 <list ordered="false">			<xsl:apply-templates select="following-sibling::*[1]/li"/>		 </list>	  </xsl:if>   </paragraph></xsl:template><xsl:template match="ul">	<xsl:if test="name(preceding-sibling::*[1])!='p'">		<xsl:if test="not(parent::p)">			<paragraph>				<list ordered="true">					<xsl:apply-templates/>				</list>			</paragraph>		</xsl:if>		<xsl:if test="parent::p">			<list ordered="true">				<xsl:apply-templates/>			</list>		</xsl:if>	</xsl:if></xsl:template><xsl:template match="li">...</xsl:template>

So I did this withouth breaking the linear barrier, so I am still interested in the question if it is possible to generate the xml using xslt where the code is non linear, what I mean is direct control of the output xml-dom so that I can insert things into nodes already created.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...