You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Gilles Dodinet <rh...@free.fr> on 2004/01/07 08:15:42 UTC

[jelly-xml] xml:copy outputs attributes as text also

hi-

im trying to transform some documents with jelly:jsl in order to modify 
the attributes of a specific element ('item'), the rest of the document 
remaining unchanged. so i have something like that in my jsl file :

<jsl:template match="/" trim="false">
    <jsl:applyTemplates select="project"/>
</jsl:template>

<jsl:template select="item">
    <!-- do stuff. works correctly -->
</jsl:template>

<jsl:template select="*">
    <!-- if currentNode.name == 'item', apply item template, else do 
this : -->
    <x:copy select=".">
       <jsl:applyTemplates />
    </x:copy>
</jsl:template>

the problem i face is that for elements different than 'item', 
attributes are outputed as text as shown below :

<menu name="menu_1">menu_1 <<===== here's the error
      <item name="item 1" href="/item_1_link"> <<=== no error for item 
transformation
</menu>

i guess the problem comes from my xsl tranformation, more particulary 
from my use of x:copy. although i cannot see what the error is. what am 
i missing ?

thanks for your help.

-- gd



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly-xml] (solved) xml:copy outputs attributes as text also

Posted by Gilles Dodinet <rh...@free.fr>.
Paul,

thank you very much for your help. i think it really helped by giving me 
ideas on how to fix the problem i was encountering. i was using jexl and 
xpath. i explain here how i solved the problem in case someone is 
interested.
i had smtg like [1] in jsl file. i used <jsl:applyTemplates select="* | 
text()"/> to ensure that attribute values were not output as text (my 
first post in this thread), and the first template was defined to make 
sure that text nodes were rendered (otherwise they didnt appear). 
however that didnt do it since text children were outputted after all 
other children. i solved that by just defining another empty template : 
<jsl:template match="@"/> and replacing the <jsl:applyTemplates 
select="* | text()"/> isntruction by this one <jsl:applyTemplates />.

this "solution" seems to work, however im not really satisfied with it, 
because it seems a bit weak. but, well, that will do it for now. thanks 
again.

[1]
--------- previous bogus templates -------------
   <jsl:template match="text()">
         <x:set var="p" select="."/>
         ${p.get(0).getText()}
   </jsl:template>
           
    <jsl:template match="*">
       <x:copy>
           <jsl:applyTemplates select="* | text()"/>
       </x:copy>
    </jsl:template>
------------------------------------------------

-- gd

Paul Libbrecht wrote:

> Gilles,
>
> Is there any reason you don't use something like the following ??
>
> <x:forEach select="$doc/img/@href" var="hrefAtt">
>     ${hrefAtt.setValue('myNewValue')}
>     </x:forEach>
>
> I've been pretty much more successful using a mix of jexl-method-calls 
> and xpath than plain-xpath with the XML-taglib. The only issue is the 
> type of the result of an XPath expression which can be very diverse...
>
> (oh, and you might be bitten by the HTML output btw... the solution is 
> dom4j-1.4 or to fix 1.4-b8).
>
> Paul




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly-xml] (solved) xml:copy outputs attributes as text also

Posted by Paul Libbrecht <pa...@activemath.org>.
Gilles,

Is there any reason you don't use something like the following ??

<x:forEach select="$doc/img/@href" var="hrefAtt">
	${hrefAtt.setValue('myNewValue')}
	</x:forEach>

I've been pretty much more successful using a mix of jexl-method-calls 
and xpath than plain-xpath with the XML-taglib. The only issue is the 
type of the result of an XPath expression which can be very diverse...

(oh, and you might be bitten by the HTML output btw... the solution is 
dom4j-1.4 or to fix 1.4-b8).

Paul


On 10-Jan-04, at 10:33 Uhr, Gilles Dodinet wrote:

> Paul,
>
> thanks for your reply. indeed im using it from within maven to 
> transform some xdoc-processed document (using also jelly:html - need 
> to change the href attribute of img elements). Ive logged in a 
> non-systematic some of the outputted elements, i will do it more 
> systematically because in fact the template i posted yesterday ("* | 
> text()") doesnot work : all text children of a given node are 
> outputted *after* all other children.. however it is perhaps my xsl 
> knowledge that is a bit light ;) so ill continue to investigate and 
> come back with the solution if i ever find it ;)
>
> regards,
>
> -- gd
>
> Paul Libbrecht wrote:
>
>> Gilles,
>>
>> There's a fair amount of possible variables that can bite you here.
>>
>> Are you using jelly within maven ? If yes, this might be infamous 
>> output bugs of dom4j 1.4b8 which is used in maven (as the release 
>> broke with entities).
>>
>> I would do something like logging the elements of your process (using 
>> the log taglib)... the dom4j' default-nodes toStrings are pretty 
>> impressing!
>> (and also expensive I think).
>>
>> Paul
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly-xml] (solved) xml:copy outputs attributes as text also

Posted by Gilles Dodinet <rh...@free.fr>.
Paul,

thanks for your reply. indeed im using it from within maven to transform 
some xdoc-processed document (using also jelly:html - need to change the 
href attribute of img elements). Ive logged in a non-systematic some of 
the outputted elements, i will do it more systematically because in fact 
the template i posted yesterday ("* | text()") doesnot work : all text 
children of a given node are outputted *after* all other children.. 
however it is perhaps my xsl knowledge that is a bit light ;) so ill 
continue to investigate and come back with the solution if i ever find 
it ;)

regards,

-- gd

Paul Libbrecht wrote:

> Gilles,
>
> There's a fair amount of possible variables that can bite you here.
>
> Are you using jelly within maven ? If yes, this might be infamous 
> output bugs of dom4j 1.4b8 which is used in maven (as the release 
> broke with entities).
>
> I would do something like logging the elements of your process (using 
> the log taglib)... the dom4j' default-nodes toStrings are pretty 
> impressing!
> (and also expensive I think).
>
> Paul




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly-xml] (solved) xml:copy outputs attributes as text also

Posted by Paul Libbrecht <pa...@activemath.org>.
Gilles,

There's a fair amount of possible variables that can bite you here.

Are you using jelly within maven ? If yes, this might be infamous 
output bugs of dom4j 1.4b8 which is used in maven (as the release broke 
with entities).

I would do something like logging the elements of your process (using 
the log taglib)... the dom4j' default-nodes toStrings are pretty 
impressing!
(and also expensive I think).

Paul


On 8-Jan-04, at 23:18 Uhr, Gilles Dodinet wrote:

> Gilles Dodinet wrote:
>
>> im trying to transform some documents with jelly:jsl in order to 
>> modify the attributes of a specific element ('item'), the rest of the 
>> document remaining unchanged. so i have something like that in my jsl 
>> file :
>>
>> <jsl:template select="*">
>>    <!-- if currentNode.name == 'item', apply item template, else do 
>> this : -->
>>    <x:copy select=".">
>>       <jsl:applyTemplates />
>>    </x:copy>
>> </jsl:template>
>>
>> the problem i face is that for elements different than 'item', 
>> attributes are outputed as text as shown below :
>>
>> <menu name="menu_1">menu_1 <<===== here's the error
>>      <item name="item 1" href="/item_1_link"> <<=== no error for item 
>> transformation
>> </menu>
>
>
> i "solved" this problem by adding a template on text nodes and doing 
> this   <x:copy select=".">
>      <jsl:applyTemplates select="* | text()/>
> </x:copy>
>
> in the  template select="*".
>
> my jsl transfo is not very elegant but still works..
>
> -- gd
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly-xml] (solved) xml:copy outputs attributes as text also

Posted by Gilles Dodinet <rh...@free.fr>.
Gilles Dodinet wrote:

> im trying to transform some documents with jelly:jsl in order to 
> modify the attributes of a specific element ('item'), the rest of the 
> document remaining unchanged. so i have something like that in my jsl 
> file :
>
> <jsl:template select="*">
>    <!-- if currentNode.name == 'item', apply item template, else do 
> this : -->
>    <x:copy select=".">
>       <jsl:applyTemplates />
>    </x:copy>
> </jsl:template>
>
> the problem i face is that for elements different than 'item', 
> attributes are outputed as text as shown below :
>
> <menu name="menu_1">menu_1 <<===== here's the error
>      <item name="item 1" href="/item_1_link"> <<=== no error for item 
> transformation
> </menu>


i "solved" this problem by adding a template on text nodes and doing 
this   
<x:copy select=".">
      <jsl:applyTemplates select="* | text()/>
</x:copy>

 in the  template select="*".

my jsl transfo is not very elegant but still works..

-- gd


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org