xsl-list
[Top] [All Lists]

[xsl] XTTE0510 ISSUE.

2008-08-18 13:44:53
Hi there, 
I have 2 xml files that need to be mixed together. 

1."Input.xml" 
"
<?xml version="1.0" encoding="UTF-8"?>
<Obj name="a">
   <Obj name="c">
        <Obj name=¡±b¡±/>
   </Obj>
</Obj>
" 

2. "testcases.xml" 
¡°
<?xml version="1.0" encoding="utf-8"?>
<Objs>
        <obj name="a" cases="a1,a2,a3"/>
        <obj name="b" cases="b1,b2"/>
        <obj name="c" cases="c1,c2"/>
</Objs>
¡° 

And I was expecting to create the output file as: 
¡° 
<TestCases> 
<Obj name=¡±a¡± case=¡±a1¡±>
     <Obj name=¡±c¡± case=¡±c1¡±>
          <Obj name=¡±b1¡±/>
          <Obj name=¡±b2¡±/>
     </Obj> 
     <Obj name=¡±c¡± case=¡±c2¡±>
          <Obj name=¡±b1¡±/>
          <Obj name=¡±b2¡±/>
     </Obj> 
</Obj> 
<Obj name=¡±a¡± case=¡±a2¡±> 
     ... 
</Obj>
....
</TestCases> 
¡° 

Here is my XSL file that does not work, 
¡° 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0">

    <xsl:output method="xml" indent="yes"/>
    <xsl:variable name="doc2"
select="document('testcases.xml')"/>
   
    <xsl:template match="/">
        <TestCases>
           <xsl:apply-templates />
        </TestCases>
   </xsl:template>

   <xsl:template match="Obj">
       <xsl:variable name="objName" select="@name"/>
       <xsl:variable name="caseString" select =
"$doc2//obj[(_at_)name = $objName]/@cases"/>
        <xsl:variable name="caseArray" 
select="tokenize($caseString, ',')"/>

       <xsl:for-each  select="$caseArray">
           <obj>
               <xsl:variable name="a"
select="position()"/>
                     <xsl:attribute name="name">
                            <xsl:value-of
select="$objName"/>
                     </xsl:attribute>
                     <xsl:attribute name="case">
                           <xsl:value-of
select="$caseArray[$a]"/>
                     </xsl:attribute>
     <xsl:apply-templates />
           </obj>
       </xsl:for-each>
   </xsl:template>

</xsl:stylesheet>
¡° 

Basically it complains for this line: 
¡° 
<xsl:apply-templates />
¡° 
as 
¡°XTTE0510: Cannot apply-templates to child nodes when
the context item is an atomic value¡±. 


Thanks a lot for the help 


Chun 




      


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--