[stringtemplate-interest] ST variable substitution issue, pls advise.

Collin Fagan collin.fagan at gmail.com
Thu Jun 23 18:51:20 PDT 2011


Hi Kiran,

Sorry for taking so long. I looked into this and discovered two things.

1. Your encoding is wrong in the header. It should be UTF-8.

<?xml version="1.0" encoding="UTF-8"?>

It's possibly that it got changed in downloading it somehere along the way,
but check just in case. If the encoding is wrong Java won't create the full
dom tree and the node model won't work.

2. I think what you really want to do is select a node with xpath then pass
that node to the next template.

Concepts: <root.("/ChangedProductNotification/product/concepts/concept"): {
concept |
     <concept.cname> <concept:apply()>
}>
>>

apply(concept) ::= <<
    Narrowing to Product Concept:
<concept.("descendant::attribute[@name='XrefValue']"): { attribute |
    * <attribute.name>,<attribute>
}>

The descendant 'axis', as it's called in xpath, selects every node that is a
child of the concept node that you passed to the apply template.

I would use this approach and not trying to build an xpath statement from
the root every time you wish to select something.

I hope this helps.

Collin


On Thu, Jun 16, 2011 at 2:09 PM, Kandru, Kiran <kiran.kandru at citi.com>wrote:

>  Hello members,
> The issue may be very small, could you please advise.
>
> Thx,
> Kiran
>
> _____________________________________________
> *From:* Kandru, Kiran [ICG-IT]
> *Sent:* Tuesday, June 14, 2011 11:02 PM
> *To:* 'stringtemplate-interest at antlr.org'
> *Subject:* ST variable substitution issue, pls advise.
>
>
> Hi,
>
> I need advise on using variable substitution into String Template file
> using XPATH Query.When I try parsing XML file , for some syntax error,
> conceptName highlighted in *RED* not being substituted by parameter passed
> to apply method. Right now I’m clueless, could you please advise?
>
>
> main(root,fldNames) ::= <<
>
>         Concepts:
> <root.("/ChangedProductNotification/product/concepts/concept"): { concept |
>                 <concept.cname:apply()>
>         }>
> >>
>
> apply(*conceptName*) ::= <<
>                 Narrowing to Product Concept:
> <root.("/ChangedProductNotification/product/concepts/concept[@cname=<*
> conceptName*>]/recs/rec/attributes/attribute[@name='XrefValue']"): {
> attribute |
>                                 <attribute.name>,<attribute>
>         }>
>
> >>
>
> Thx,
> Kiran
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110623/4e8a08e6/attachment-0001.html 


More information about the stringtemplate-interest mailing list