RE: [xsl] Different conditional outputs in same Stylesheet or calling another stylesheet (version 1.0, Xalan)

Subject: RE: [xsl] 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 18:19:55 +0530
Hi,

I think I am still not clear with the use of "mode' attribute. As per
understanding "mode" is used when you want to perform a conditional
transformation on a particular or group of nodes by APPLYING that mode to
those elements.

For example taking the same example, below how my XSL looks like:


<xsl:template match="article/meta/journalcode">
	<xsl:if test="string(.)='CEDE'">
		<xsl:copy>
			<xsl:apply-templates mode="CEDE"/>
		</xsl:copy>
	</xsl:if>
</xsl:template>


And it applying to the following template

  <xsl:template match="article/references[@id='references']/ref-book"
mode="CEDE">
	<!-- Do Something //-->
  </xsl:template>

it doesn't seems to be working. Although if remove mode="CEDE" everything
seems to be perfect. My requirement is;

1/ Apply what ever defined, whether mode condition is true or not (like
<artcle> and other elements here)
2/ Change those according to the mode condition whenever tested (<ref-book>
here check "CHANGE HERE ONLY" )


My Complete stylesheet looks like some thing below:



<?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:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>

	<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">
	<xsl:if test="string(.)='CEDE'">
		<xsl:copy>
			<xsl:apply-templates mode="CEDE"/>
		</xsl:copy>
	</xsl:if>
	</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>


	<!-- CHANGE HERE ONLY CHANGE HERE ONLY CHANGE HERE ONLY CHANGE HERE ONLY
CHANGE HERE ONLY CHANGE HERE ONLY CHANGE HERE ONLY   //-->

  <xsl:template match="article/references[@id='references']/ref-book">
	<!-- Do Something //-->
  </xsl:template>
  <!-- omit these -->

  <xsl:template match="author-ref">
	<!-- Do Something //-->
  </xsl:template>

  <!-- an identity template for each mode -->


  <xsl:template match="@*|node()" mode="CEDE">
   <xsl:copy>
    <xsl:apply-templates select="@*|node()" mode="CEDE"/>
   </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()">
   <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
  </xsl:template>

</xsl:stylesheet>



Thanks,
Pankaj





















Pankaj Chaturvedi schrieb:

You may detect the different journal codes using simple tests and then
branch into different modes to process accordingly.

I don't know if this is the best approach. Its viability may depend
on how much reshaping is required for your different journal codes.

Michael

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

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

  <xsl:template match="article[ .//journalcode = 'EHEF' ]">
   <xsl:comment>EHEF</xsl:comment>
   <xsl:copy>
    <xsl:apply-templates mode="EHEF"/>
   </xsl:copy>
  </xsl:template>

  <!-- join authorfield, year, chaptitle, booktitle -->
  <xsl:template match="ref-book" mode="CEDE">
   <xsl:copy>
    <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 mode="CEDE"/>
   </xsl:copy>
  </xsl:template>
  <!-- omit these -->
  <xsl:template match="authorfield | year | chaptitle | booktitle"
   mode="CEDE"/>

  <!-- do special stuff for EHEF -->
  <!-- ... -->

  <!-- Maybe sufficient for all journal codes? -->
  <xsl:template match="author-ref">
   <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="givenname"/>
    <xsl:apply-templates select="surname"/>
   </xsl:copy>
  </xsl:template>

  <!-- an identity template for each mode -->

  <xsl:template match="@*|node()" mode="EHEF">
   <xsl:copy>
    <xsl:apply-templates select="@*|node()" mode="EHEF"/>
   </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()" mode="CEDE">
   <xsl:copy>
    <xsl:apply-templates select="@*|node()" mode="CEDE"/>
   </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()">
   <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
  </xsl:template>

</xsl:stylesheet>


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