[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Weired Result of XSLT

Subject: Re: Weired Result of XSLT
From: "J. S. Rawat" <jrawat@xxxxxxxxxxxxxx>
Date: Tue, 22 May 2007 13:09:39 +0530
Re:  Weired Result of XSLT
Lot of thanks for your nice clue !!! I have written <xsl:strip-space elements="*"/> and it is working fine.

At 03:24 PM 5/22/2007 +0800, you wrote:
Your problem is a FAQ. Maybe this could help clear things up:

http://www.dpawson.co.uk/xsl/sect2/N6099.html#d9172e70

--
Jeff

Jeff Sese wrote:
In your xsl you are testing if the position() of the contrib element is either = or > 1 however from your example all of the contrib elements have position() greater than one thus the second xsl:if
statement kicks in.


If you want to check, insert this in your template for contrib:

<position><xsl:sequence select="position()"/></posistion>

Try it to check if the position() function returns a value you assume it returns.
--
Jeff



J. S. Rawat wrote:
Dear Jeff I have removed the CR and got the result but I don't think that this the case. It is working fine with my other XSLTs.

At 02:57 PM 5/22/2007 +0800, you wrote:
The output is correct, you failed to consider the text node inside the contib-group element. In the contrib-group element there are four nodes; the CR before the fisrt contrib element, the first contrib element, the CR before the second contrib element and then the second contrib element. So when the template matches the contrib elements the position returned is 2 and 4 respectively. What you want would be:

count(preceding-sibling::contrib) = 0 ---> would return the first contrib

I hope this helps.

--
Jeff

J. S. Rawat wrote:
Dear Lists-
Thanks in advance as I get all solutions of my problems by this lists only. Today I am hang-up in a weired problem as I am not able to find out the problem in xslt. Please let me know what is wrong in the xslt.


Command line
java -jar saxon8.jar a.xml b.xsl >c.xml

INPUT
<article article-type="review-article">
<contrib-group>
<contrib>
<name>
<surname>aaaaa</surname>
<given-names>xxxx</given-names>
</name>
</contrib>
<contrib>
<name>
<surname>bbbb</surname>
<given-names>yyyy</given-names>
</name>
</contrib>
</contrib-group>
</article>

XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<head>
<xsl:apply-templates select="//contrib-group"/>
</head>
</xsl:template>


    <xsl:template match="//contrib-group">
        <contributors>
            <xsl:apply-templates/>
        </contributors>
    </xsl:template>

    <xsl:template match="contrib">
        <xsl:if test="position()=1">
            <person_name sequence="first" contributor_role="author">
                <xsl:apply-templates select="name"/>
            </person_name>
        </xsl:if>
        <xsl:if test="position()&gt;1">
            <person_name sequence="additional" contributor_role="author">
                <xsl:apply-templates select="name"/>
            </person_name>
        </xsl:if>
    </xsl:template>

    <xsl:template match="contrib-group/contrib/name">
        <xsl:if test="given-names">
            <given_name>
                <xsl:apply-templates select="given-names"/>
            </given_name>
        </xsl:if>
        <surname>
            <xsl:apply-templates select="surname"/>
        </surname>
        <xsl:if test="suffix">
            <suffix>
                <xsl:apply-templates select="suffix"/>
            </suffix>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

OUTPUT
<?xml version="1.0" encoding="UTF-8"?>
<head xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <contributors>
      <person_name sequence="additional" contributor_role="author">
         <given_name>xxxx</given_name>
         <surname>aaaaa</surname>
      </person_name>
      <person_name sequence="additional" contributor_role="author">
         <given_name>yyyy</given_name>
         <surname>bbbb</surname>
      </person_name>
   </contributors>
</head>

Desired Output
<?xml version="1.0" encoding="UTF-8"?>
<head xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <contributors>
      <person_name sequence="first" contributor_role="author">
         <given_name>xxxx</given_name>
         <surname>aaaaa</surname>
      </person_name>
      <person_name sequence="additional" contributor_role="author">
         <given_name>yyyy</given_name>
         <surname>bbbb</surname>
      </person_name>
   </contributors>
</head>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.