Re: [xsl] [xslt] not working transformation when function called

Subject: Re: [xsl] [xslt] not working transformation when function called
From: Michalmas <michalmas@xxxxxxxxx>
Date: Fri, 20 Mar 2009 00:05:01 +0100
Update: the code was working, but i used the wrong node name. that's
the reason i haven't received any results...

On Thu, Mar 19, 2009 at 10:40 PM, Michalmas <michalmas@xxxxxxxxx> wrote:
> Hi all,
>
> I see that in example i put all templates for copy on top. In fact, i
> had different structure and the calling the template i wanted was
> working. Also, the XML i used is only part of big XML structure, and
> that part is repeated many times.
>
> To clear it up:
> i have following code:
> <xsl:template match="*">
>
> <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
>
> </xsl:template>
>
>
> <xsl:template match="move">
> B  <xsl:variable name="names" select=".//dataname" />
> B  B  B  B <datatype><xsl:value-of
select="local:getNodeType(/,$names)"/></datatype>
> </xsl:template>
>
>
> B <xsl:function name="local:getNodeType">
> B  B  B  B  B  B  B  B  B  <xsl:param name="node" as="node()*"/>
> B  B  B  B  B  B  B  B  B  <xsl:param name="searchValue" as="xs:string*"/>
>
> B  B  B  <xsl:choose>
> B  B  B  B  B  <xsl:when test="empty($searchValue)">
> B  B  B  B  B  B  B  <xsl:sequence select="$node/pic-value"/>
> B  B  B  B  B  </xsl:when>
> B  B  B  B  B  <xsl:otherwise>
> B  B  B  B  B  B  B  <xsl:sequence
> select="local:getNodeType($node//data-declaration[name=$searchvalue[1]][1],
> $searchValue[postion() != 1])"/>
> B  B  B  B  B  </xsl:otherwise>
> B  B  B  </xsl:choose>
> B </xsl:function>
>
> </xsl:stylesheet>
>
>
> applied on that XML:
> <someNodes>
> (...)
> B  B  <move>
> B  B  B  B  B  B  B  <from>
> B  B  B  B  B  B  B  B  B <dataname>01</dataname>
> B  B  B  B  B  B  B  B  B <dataname>02</dataname>
> B  B  B  B  B  B  B  </from>
> B  B  B  B  B  B  B  <to>
> B  B  B  B  B  B  B  B  <qualification>
> B  B  B  B  B  B  B  B  B  <dataname>001</dataname>
> B  B  B  B  B  B  B  B  B  <dataname>002</dataname>
> B  B  B  B  B  B  B  B  </qualification>
> B  B  B  B  B  B  B  </to>
> B  B  </move>
> (...)
> </someNodes>
>
>
> And i want to tranform it to:
> <move>
> B  B  B  B  B  B  B <from datatype='XXX'> <!-- VALUE RETURNED BY
> local:getNodeType FUNTION -->
> B  B  B  B  B  B  B  B  <dataname>01</dataname>
> B  B  B  B  B  B  B  B  <dataname>02</dataname>
> B  B  B  B  B  B  B </from>
> B  B  B  B  B  B  B <to>
> B  B  B  B  B  B  B  B <qualification datatype='ZZZ'> <!-- VALUE RETURNED
BY
> local:getNodeType FUNTION -->
> B  B  B  B  B  B  B  B  B <dataname>001</dataname>
> B  B  B  B  B  B  B  B  B <dataname>002</dataname>
> B  B  B  B  B  B  B  B </qualification>
> B  B  B  B  B  B  B </to>
> B </move>
>
>
> thanks!
>
> On Thu, Mar 19, 2009 at 10:26 PM, Christopher R. Maden <crism@xxxxxxxxx>
wrote:
>> Michalmas wrote:
>>> But why this trigger:
>>>
>>> <xsl:template match="move/from">
>>> B  <datatype><xsl:value-of select="local:getNodeType(/,
>>> ./dataname)"/></datatype> <!--DATATYPE -->
>>> </xsl:template>
>>>
>>> doesn't work?
>>
>> You should probably review some basic texts, just as Jeni Tennisonbs,
>> Michael Kaybs, or Ken Holmanbs; there seems to be some confusion about
>> the basic XSLT processing model.
>>
>> To elaborate on what David Carlisle said:
>>
>> You have a template that matches /, the document node. B It says to apply
>> templates (to its children).
>>
>> The first child encountered is move. B There is no template that
>> explicitly matches move; instead, the template matching * is used. B That
>> template says to copy the element. B Thus, the entire move element is
copied.
>>
>> And... thatbs it. B There are no more children of /, so nothing else is
done.
>>
>> You probably want, as I suggested, to nuke the * template and allow the
>> default template to apply, or else use the identity transformation
>> (which is available in a thousand places with a quick Web search) as
>> your starting point.
>>
>> ~Chris
>> --
>> Chris Maden, text nerd B <URL: http://crism.maden.org/ >
>> bAll I ask of living is to have no chains on me,
>> B And all I ask of dying is to go naturally.b b Laura Nyro
>> GnuPG Fingerprint: C6E4 E2A9 C9F8 71AC 9724 CAA3 19F8 6677 0077 C319

Current Thread