xsl-list
[Top] [All Lists]

Re: [xsl] xsl: parsing through specific child nodes

2008-09-08 12:48:22
So I tried various things but it doesn't seem to be working. I'll give
the complete information:

1. xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Msg xmlns:ns2="http://www.abc.com/wsdl/v";>
<Msg>
               <cid>103850015_0_1219420995471</cid>
               <fid>41</fid>
               <filing>IS</filing>
               <State>PENDING</State>
            </Msg>
</Msg>

2. xsl file:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
exclude-result-prefixes="xmlns:ns2 ns2 xmlns">
<xsl:output method="xml" indent="yes" />
<xsl:variable name="file2" select="document('EFF')" />
<xsl:key name='PENDING' match='Msg' use='./State'/>
<xsl:template match="/">
   <xsl:choose>
    <xsl:when test="not(//State='PENDING')
                and not(//State='SUCCEDED')">
       <ret>
          <xsl:copy-of select="//ret/*" />
       </ret>
    </xsl:when>
    <xsl:when test="not($file2//State='PENDING')
                and not($file2//State='SUCCEDED')">
       <ret>
          <xsl:copy-of select="$file2//ret/*" />
       </ret>
    </xsl:when>
    <xsl:otherwise>
          <xsl:apply-templates select="//ret"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
<xsl:template match="ret">
       <xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="*">
 <xsl:copy>
   <xsl:choose>
     <xsl:when test="text()='PENDING'">
             <xsl:text>1</xsl:text>
     </xsl:when>
   <xsl:otherwise>
     <xsl:copy-of select="." />
   </xsl:otherwise>
  </xsl:choose>
 </xsl:copy>
</xsl:template>
</xsl:stylesheet>

3. Output:
<?xml version="1.0" encoding="UTF-8"?>
<Msg xmlns:ns2="http://www.abc.com/wsdl/v";>
<Msg>
               <cid>103850015_0_1219420995471</cid>
               <fid>41</fid>
               <filing>IS</filing>
               <State>PENDING</State>
            </Msg>
</Msg>

4.expected output:

<?xml version="1.0" encoding="UTF-8"?>
<Msg>
               <cid>103850015_0_1219420995471</cid>
               <fid>41</fid>
               <filing>IS</filing>
               <State>1</State>
            </Msg>
</Msg>


First I don't understand how there are 2 Msg nodes. And second I
wasn't able to get rid of namespace node by using <element> as
suggested by Michael, it's still copying the namespace node.
On Mon, Sep 8, 2008 at 6:52 AM, Mukul Gandhi 
<gandhi(_dot_)mukul(_at_)gmail(_dot_)com> wrote:
On Mon, Sep 8, 2008 at 1:16 AM, Mohit Anchlia 
<mohitanchlia(_at_)gmail(_dot_)com> wrote:
1. So would above template mentioned by Mukul also output node HIJ ?

I think, "outputting the node" is not the correct terminology. We can
copy the node to the result tree, or write something else to the
result tree, derived from the properties of the input nodes.

      <xsl:when test="local-name()="HIJ" and . = 'YYYYYY'">

This statement will probably not compile, as I can see some misplaced quotes.


3. Currently I am using XSLT 1.0 and I am using JAXP which uses Xalan.
How do I start using XSLT 2.0.

You need to download an XSLT 2.0 processor, like Saxon and using it as
described in the documentation.

Would it just be matter of upping version in stylesheet node?

No. version="2.0" is just a hint to the processor. You need to supply
the XSLT 2.0 stylesheet to a XSLT 2.0 processor like Saxon.


--
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--