Subject: [xsl] Re: following-sibling on attributes From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Tue, 9 Sep 2003 06:25:25 +0200 |
Vidar, As you have changed significantly my code and the context it is used in, I cannot answer questions about the behaviour of the new code. I am happy that I was able to help you, but please, ask questions that only concern the code I posted. If your question: > Dimitre, are you sure that these lines in your reply > > > <xsl:otherwise> > > <xsl:value-of select=".."/> > </xsl:otherwise> > > shouldn't be > > <xsl:otherwise> > <xsl:value-of select="."/> > </xsl:otherwise> is about the code that I posted, the answer is that it must be: <xsl:otherwise> <xsl:value-of select=".."/> </xsl:otherwise> because the current node is an attribute and we want to produce the string value of the element, that has this attribute. ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL "Vidar S. Ramdal" <vidar@xxxxxxxx> wrote in message news:3F5C9123.7050908@xxxxxxxxxxx > Som Dimitre Novatchev sa den 08.09.2003 13:56: > >>Dimitre, are you sure that these lines in your reply > > >> <xsl:otherwise> > >> <xsl:value-of select=".."/> > >> </xsl:otherwise> > > >>shouldn't be > >> > >><xsl:otherwise> > >> <xsl:value-of select="."/> > >></xsl:otherwise> > > > > Yes, I am definitely, absolutely sure. In this case (and typically) I do > > not post untested and not working code. > > > > What problem do you see with this code? > > > > Didn't you run the transformation to see that it produces the wanted > > result? > > Yes, I did, and without changing your code I get an error when trying to > parse the results of the transformation into a JDOM tree. However, > changing to <xsl:value-of select="."/> everything works as expected, and > I'm happy as a lark. > > Right now, my mind is too blurry to see why that happens. > > But perhaps I was not clear about the context in which the templates are > used. Below is the entire code: > > > <xsl:template match="IPS:TEXT"> > > <xsl:choose> > > <xsl:when test="@*"> > > <xsl:call-template name="TEXT_ATTRIBUTE_TO_ELEMENT"> > > <xsl:with-param name="attList" select="@*"/> > > </xsl:call-template> > > </xsl:when> > > <xsl:otherwise> > > <xsl:apply-templates/> > > </xsl:otherwise> > > </xsl:choose> > > </xsl:template> > > > > > > <!-- Suggested by Dimitri Novatsjev > > http://www.biglist.com/lists/xsl-list/archives/200309/msg00243.html --> > > > > <xsl:template name="TEXT_ATTRIBUTE_TO_ELEMENT"> > > <xsl:param name="attList" select="/.."/> > > <xsl:if test="$attList"> > > <xsl:variable name="elementname"><xsl:apply-templates select="$attList[1]" mode="ELEMENTNAME"/></xsl:variable> > > <xsl:variable name="attributes"> > > <xsl:apply-templates select="$attList[1]" mode="ATTRIBUTES"/> > > </xsl:variable> > > <xsl:element name="{$elementname}"> > > <xsl:for-each select="$attributes/attr"> > > <xsl:attribute name="{@name}"><xsl:value-of select="."/></xsl:attribute> > > </xsl:for-each> > > <xsl:choose> > > <xsl:when test="$attList[2]"> > > <xsl:call-template name="TEXT_ATTRIBUTE_TO_ELEMENT"> > > <xsl:with-param name="attList" > > select="$attList[position() > 1]"/> > > </xsl:call-template> > > </xsl:when> > > <xsl:otherwise> > > <xsl:value-of select="."/> > > </xsl:otherwise> > > </xsl:choose> > > </xsl:element> > > </xsl:if> > > </xsl:template> > > > > <!-- Templates below are used to change IPS:TEXT attributes into proper XHTML elements --> > > <xsl:template match="IPS:TEXT/attribute::node()" mode="ELEMENTNAME"><xsl:value-of select="local-name()"/></xsl:template> > > <xsl:template match="IPS:TEXT/@URL" mode="ELEMENTNAME">a</xsl:template> > > <xsl:template match="IPS:TEXT/@B" mode="ELEMENTNAME">b</xsl:template> > > <xsl:template match="IPS:TEXT/@I" mode="ELEMENTNAME">i</xsl:template> > > <xsl:template match="IPS:TEXT/@U" mode="ELEMENTNAME">u</xsl:template> > > <xsl:template match="IPS:TEXT/@TARGET" mode="ELEMENTNAME"/> <!-- TARGET is not an element, but is handled by @URL --> > > > > <xsl:template match="IPS:TEXT/attribute::node()" mode="ATTRIBUTES"/> <!-- Most XHTML elements have no attributes --> > > > > <xsl:template match="IPS:TEXT/@URL" mode="ATTRIBUTES"> > > <attr name="href"><xsl:value-of select="."/></attr> > > <xsl:if test="../@TARGET"> > > <attr name="target"><xsl:value-of select="../@TARGET"/></attr> > > </xsl:if> > > </xsl:template> > > Sample XML fragment: > > > <IPS:TEXT B="1" I="1">Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</IPS:TEXT> > > <IPS:TEXT URL="ps://237;393" TARGET="_blank">Lorem ipsum dolor sit amet.</IPS:TEXT> > > <IPS:TEXT B="1">Lorem ipsum dolor sit amet</IPS:TEXT> > > This transforms very nicely into: > > > <b><i>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet</i></b> > > <a href="ps://237;393" target="_blank">Lorem ipsum dolor sit amet.</a> > > <b>Lorem ipsum dolor sit amet</b> > > -- > Vidar S. Ramdal <vidar@xxxxxxxx> > Idium AS - http://www.idium.no > Tlf. +47 22 00 84 00 / Fax: +47 22 00 84 01 > A: Top posting. > Q: What is the most annoying thing on usenet and in e-mail? > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] following-sibling on attr, Vidar S. Ramdal | Thread | Re: [xsl] Re: following-sibling on , Vidar S. Ramdal |
RE: [xsl] Automatically copying an , Michael Kay | Date | [xsl] limit count() to nodes with a, M. David Peterson |
Month |