Problem is, that the 'select' attribute of xsl:value-if is not 
interpolated. I'll try to find another way.

PH

Honza Pazdziora wrote:

> Hello,
> 
> I'd like to reference elements whose names (paths) are not known
> statically but are stored in the XML document. I have following XML:
> 
>         <?xml version="1.0" encoding="ISO-8859-2"?>
>         <page>
>                 <result>
>                         <person>Tom</person>
>                         <id>13</id>
>                 </result>
>                 <structure>
>                         <tag name="person"/>
>                         <tag name="id"/>
>                 </structure>
>         </page>
> 
> and I'm aiming for the output
> 
>         <output>
>                 <newtag name="person" value="Tom"/>
>                 <newtag name="id" value="13"/>
>         </output>
> 
> so if the /page/structure/tag/@name is person, the value of th nwatag
> should be /page/result/person. I tried
> 
>         <?xml version="1.0"?>
>         <xsl:stylesheet version="1.0" 
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 
>         <xsl:template match="page">
>         <output>
>                 <xsl:apply-templates select="structure"/>
>         </output>
>         </xsl:template>
> 
>         <xsl:template match="structure/tag">
>                 <newtag>
>                 <xsl:attribute name="name">
>                         <xsl:value-of select="@name"/>
>                 </xsl:attribute>
>                 <xsl:attribute name="value">
>                         <xsl:value-of select="/page/result/{@name}"/>
>                 </xsl:attribute>
>                 </newtag>
>         </xsl:template>
> 
>         </xsl:stylesheet>
> 
> but received [Sablotron] [215] Error: msgtype:error ::
> code:215 :: module:Sablotron :: URI:arg:/template :: line:16 ::
> node:attribute 'select' :: msg:token '{' not recognized
> (this is in XML::Sablotron under AxKit but I assume it doesn't
> matter).
> 
> Jirka Kosek suggested using
> 
>          <xsl:template match="structure/tag">
>                  <xsl:variable name="name" select="@name"/>
>                  <newtag>
>                  <xsl:attribute name="name">
>                          <xsl:value-of select="$name"/>
>                  </xsl:attribute>
>                  <xsl:attribute name="value">
>                          <xsl:value-of select="/page/result/$name"/>
>                  </xsl:attribute>
>                  </newtag>
>          </xsl:template>
> 
> but here I get [Sablotron] [214] Error: msgtype:error :: code:214 ::
> module:Sablotron :: URI:arg:/template :: line:17 :: node:attribute
> 'select' :: msg:pattern is empty
> (line 17 that containing <xsl:value-of select="/page/result/$name"/>).
> 
> So my question is: is this possible with Sablotron? Using data from
> XML to dynamically with the target of the template of the path of the
> element? Or any other workaround?
> 
> Any hint would be helpful,
> 
> 

-- 
Pavel Hlavnicka
Ginger Alliance Ltd.
Prague; Czech Republic

Reply via email to