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

RE: FW: Different conditional outputs in same Stylesh

Subject: RE: FW: Different conditional outputs in same Stylesheet or calling another stylesheet (version 1.0, Xalan)
From: "Pankaj Chaturvedi" <pankaj.chaturvedi@xxxxxxxxx>
Date: Fri, 29 Feb 2008 12:36:27 +0530
RE:  FW:  Different conditional outputs in same Stylesh
Well guys I think I got a clue. I have been wrongly using
 <xsl:template match="article[ .//journalcode = 'CEDE' ]">
        <xsl:apply-templates mode="in-cede"/>
  </xsl:template>

which was actually overriding the effect of template

      <xsl:template match="article">
                <xsl:element name="article">
                        <xsl:attribute name="aid:cstyle"/>
                        <xsl:copy-of select="@*"/>
                        <xsl:apply-templates/>
                </xsl:element>
        </xsl:template>

The correct way is


<xsl:template match="journalcode = 'CEDE' ">
	<xsl:apply-templates select="." mode="in-cede"/>
  </xsl:template>

This has been suggested earlier also but seems to misread by me.

Thanks anyway.

Pankaj





-----Original Message-----
From: Pankaj Chaturvedi [mailto:pankaj.chaturvedi@xxxxxxxxx]
Sent: Friday, February 29, 2008 10:27 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  FW: Different conditional outputs in same Stylesheet or
calling another stylesheet (version 1.0, Xalan)


Hi again,

I think I am having one of those days as I am completly lost.

Coming back to my same example, I have tried a combination of methods, which
Michael and drkm has suggested me. I certainly want all "modes" to be
defined in different style sheet, as lots of manipulation is required (this
is simple example). Below is my source and two stylesheets to handle the
references and other elements. I've also tried to use <xsl:include> and
<xsl:call-template> to modularize the things but seems not to be correctly
used. I am newbie in XSLT.

XML Source:
============
<?xml version="1.0" encoding="UTF-8"?>
<article>
<meta>
<journalcode>CEDE</journalcode>
<issn type="print">XXXX-XXXX</issn>
</meta>
<references article-association="a259587"
id="references"><title>References</title>
<ref-book id="CIT0001">
<authorfield>
<author-ref>
<surname>Bergstrom</surname><givenname>T.C.</givenname>
</author-ref></authorfield>
<chaptitle>xxxxx</chaptitle> <booktitle>yyyyyyy</booktitle>
<publicationfield>
<pubname>uuuu</pubname>
<pubplace><city>Amsterdam</city></pubplace>
<year>1997</year><volumenum>1A</volumenum></publicationfield>
<pagefield>
<firstpage/>
</pagefield>
</ref-book>
</references>
</article>


main.xsl (which is including the cede.xsl)
============================================

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:strip-space elements="*"/>
        <xsl:preserve-space elements="*"/>

<xsl:include href="cede.xsl"/>

<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>

<!--  Process construct element and add the custom attribute, copy existing
attributes and continue processing  //-->

        <xsl:template match="article">
                <xsl:element name="article">
                        <xsl:attribute name="aid:cstyle"/>
                        <xsl:copy-of select="@*"/>
                        <xsl:apply-templates/>
                </xsl:element>
        </xsl:template>

<xsl:template match="article/meta/journalcode*[text()]">
                <xsl:copy>
                        <xsl:copy-of select="@*"/>
                        <xsl:attribute name="dummy">
                                <xsl:value-of select="string(.)"/>
                        </xsl:attribute>
                </xsl:copy>
</xsl:template>

<xsl:template match="article/meta/issn[@type='print']code*[text()]">
                <xsl:copy>
                        <xsl:copy-of select="@*"/>
                        <xsl:attribute name="dummy">
                                <xsl:value-of select="string(.)"/>
                        </xsl:attribute>
                </xsl:copy>
</xsl:template>


<xsl:template match="article/references[@id='references']/title">
        <char><xsl:text>&#x0000A;</xsl:text></char>
                <xsl:element name="title">
                        <xsl:attribute
name="aid:pstyle">ref_head</xsl:attribute>
                        <xsl:copy-of select="@*"/>
                        <xsl:apply-templates/>
                </xsl:element>
</xsl:template>


 <xsl:template match="article[ .//journalcode = 'CEDE' ]">
        <xsl:apply-templates mode="in-cede"/>
  </xsl:template>

 <xsl:template match="article/references[@id='references']/ref-book"
mode="in-cede">
<xsl:element name="ref-book">
<xsl:attribute name="aid:pstyle">ref</xsl:attribute>
        <xsl:call-template name="ref-book-cede"/>
</xsl:element>
    </xsl:template>

  <xsl:template match="author-ref">
      <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="givenname"/>
    <xsl:text>, </xsl:text>
    <xsl:apply-templates select="surname"/>
  </xsl:copy>
  </xsl:template>

  <!-- omit these -->

 <xsl:template match="authorfield | year | chaptitle | booktitle"
   mode="in-cede"/>


<!-- first template copies input to output -->
        <xsl:template match="text()*|@*">
                <xsl:copy>
                        <xsl:apply-templates select="text()|*|@*"/>
                </xsl:copy>
        </xsl:template>

<!--  END END END END END END END END END END END END END END END END END
END END END END END END END END END END END END END END    //-->
</xsl:stylesheet>

cede.xsl
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>

<xsl:template name="ref-book-cede" mode="in-cede">
     <xsl:copy-of select="@*"/>
 <xsl:apply-templates select="authorfield"/>
     <xsl:text>, </xsl:text>
     <xsl:apply-templates select=".//year"/>
     <xsl:text>. </xsl:text>
     <xsl:apply-templates select="chaptitle"/>
     <xsl:text>, In: </xsl:text>
     <xsl:apply-templates select="booktitle"/>
 <xsl:apply-templates/>
 </xsl:template>
</xsl:stylesheet>

Result I am getting:
<?xml version="1.0" encoding="UTF-8"?>CEDEXXXX-XXXXReferences
<ref-book xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
aid:pstyle="ref"
id="CIT0001"><authorfield><author-ref><givenname>T.C.</givenname>,
<surname>Bergstrom</surname></author-ref></authorfield>, <year>1997</year>.
<chaptitle>xxxxx</chaptitle>, In:
<booktitle>yyyyyyy</booktitle><authorfield><author-ref><givenname>T.C.</give
nname>,
<surname>Bergstrom</surname></author-ref></authorfield><chaptitle>xxxxx</cha
ptitle><booktitle>yyyyyyy</booktitle><publicationfield><pubname>uuuu</pubnam
e><pubplace><city>Amsterdam</city></pubplace><year>1997</year><volumenum>1A<
/volumenum></publicationfield><pagefield><firstpage/></pagefield></ref-book>

As you notice the following are errors in resulting output:
1. <authorfield>, <chaptitle> and ><booktitle> title is repeating
themselves.
2. <ref-book> becomes the root element, only text is left
(CEDEXXXX-XXXXReferences) in output with missing transformation I am trying
to other elements (attributes aid:pstyle).
I am sure that I am not correctly using the <xsl:call-template> , which
actually suppressing the effect of below code:

<!-- first template copies input to output -->
        <xsl:template match="text()*|@*">
                <xsl:copy>
                        <xsl:apply-templates select="text()|*|@*"/>
                </xsl:copy>
        </xsl:template>
My actual xml souce and stylesheet are huge ones and I am almost done with
all requirements, leaving only the reference part, for which I am trying my
hands for the past few days. I am also going thru the books and topics but
seems to be lost my mind.
 Can somebody guide me, whether this is correct way of defining "mode" and
calling them with <xsl:call-template>, because as soon as I comment it I get
the correct output for rest of elements but missing the references.
Any help in this regard will be highly appreciated.

regards,
Pankaj




-----Original Message-----
From: Pankaj Chaturvedi [mailto:pankaj.chaturvedi@xxxxxxxxx]
Sent: Wednesday, February 27, 2008 5:10 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Different conditional outputs in same Stylesheet or
calling another stylesheet (version 1.0, Xalan)


Thanks Michael as well as drkm for suggestions. It was an immense help.

Let me work out with small test files and will decide what to opt.

Thanks again and have a great day ahead.

Pankaj



-----Original Message-----
From: Michael Ludwig [mailto:mlu@xxxxxxxxxxxxx]
Sent: Wednesday, February 27, 2008 4:32 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Different conditional outputs in same Stylesheet or
calling another stylesheet (version 1.0, Xalan)


Pankaj Chaturvedi schrieb:
> Thanks Michael for the detailed explanation. Never used "mode"
> attribute but seems to perfect in my case.
>
> One more question, don't you think that <xsl:import> or <xsl:include>
> (although I still do not know much about these two elements) will be
> more helpful in this case to avoid the long and complex stylesheet. I
> would prefer to modularize this rather having a single stylesheet,
> which later will be painful, if debugging is required.

Personally, I don't think that splitting code up into different
stylesheets is a guarantee for less pain. But then, I'm not a very
experienced XSL user.

But of course it may look more orderly to you. And if that is the
purpose, why not go ahead and use xsl:include? To give an example, you
might organise your different modes in stylesheets by the same name.

An xsl:import is used to override definitions in the calling stylesheet.
An xsl:include is just a simple inclusion. Which one is better for you,
depends on your approach. If unsure, pick xsl:include, which is simpler
in concept.

Michael


Confidentiality Notice:" This message and any attachment(s)
contained here are information that is confidential, proprietary to
IDS Infotech Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the entity it
is addressed to. If you are not the intended recipient of this
message, you are not authorized to read, forward, print, retain,
copy or disseminate this message or any part of it. If you have
received this e-mail in error, please notify the sender immediately
by return e-mail and delete it from your computer."

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.