Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2006, 09:17 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to control optional elements and attributes

Dear all,

Sorry that I am asking many questions today but unfortunately I have another problem.

I am having two optional attributes and they are giving me source and image link of the external icons. I am gonna write down the XSL again but if you want to see the XML file it is the same XML at the loop in XSL topic

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fcs="urn:factiva:developer:v3_0:parsers" xmlns:msxsl="urn:schemas-microsoft-com:xslt" >
<xsl:output method="html" version="4.0" />
<xsl:template match ="/">
<xsl:apply-templates select="SOAP-ENV:Envelope/SOAP-ENV:Body/fcs:GetArticleResponse/fcs:articleResponse/fcs:articleResultSet/fcs:article"></xsl:apply-templates>
</xsl:template>
<xsl:template match="SOAP-ENV:Envelope/SOAP-ENV:Body/fcs:GetArticleResponse/fcs:articleResponse/fcs:articleResultSet/fcs:article">
    <head>
            <title>Factiva Test</title>
            <link href='http://intranet1-t.internal.epo.org/portal/themes/html/epoIntranetCD/cssTheme.css' rel="stylesheet" type="text/css" />
            <link href='http://intranet1-t.internal.epo.org/portal/themes/html/epoIntranetCD/cssPageBody.css' rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="epoContentStandard">
        <img src="http://dg1-2.internal.epo.org/_test/Huerol/Factiva/flogostyle1.gif" align="right" />
        <br clear="all"/>
     <xsl:if test="fcs:logo/@source != ''">
        <xsl:variable name="logosource" select="fcs:logo/@source"/>
        <xsl:variable name="logoimage" select="fcs:logo/@image"/>
        <xsl:variable name="logo" select="'fcs:logo/@source'+'/'+'$logoimage'"/>
        <img src= "$logo"/>
        </xsl:if>
         <h1 style="margin-bottom:0.3ex;"><xsl:value-of select="fcs:headline/fcs:paragraph"/></h1>
        <p style="margin-bottom:3.5ex;font-size:80%;color:#888888;"><xsl:value-of select="fcs:copyright"/></p>
    <xsl:apply-templates select="//fcs:leadParagraph"/>
    <xsl:apply-templates select="//fcs:tailParagraphs"/>
    <div id="epoFooter">
    <a href='http://www.factiva.com/termsofuse'>Terms of use</a>&nbsp; &copy;200X Dow Jones Reuters Business Interactive LLC (trading as Factiva). All rights reserved.
    </div>
        </div>
    </body>
</xsl:template>
<xsl:template match="fcs:leadParagraph">
    <p><strong>
     <xsl:apply-templates select="fcs:paragraph"/>
     </strong>
    </p>
</xsl:template>
<xsl:template match="fcs:tailParagraphs">
    <p>
     <xsl:apply-templates select="fcs:paragraph"/>
    </p>
</xsl:template>

<xsl:template match="fcs:paragraph">
     <p>
        <xsl:value-of select="."/>
     </p>
</xsl:template>

</xsl:stylesheet>

1) What should I write in xsl:if statement
2) How can I add 2 variable with "/" to get a logo variable for img src?


Your attitude determines your altitude
__________________
Your attitude determines your altitude
 
Old September 2nd, 2006, 12:08 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I haven't tried to follow the logic in detail. But there's some obvious nonsense here:

<xsl:variable name="logo" select="'fcs:logo/@source'+'/'+'$logoimage'"/>


Firstly, "+" does not do string concatenation in XPath. You want the concat() function. Secondly, there doesn't seem to be any reason to put the first expression in quotes.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 2nd, 2006, 12:09 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This line is wrong too:

<img src= "$logo"/>

It should be

<img src= "{$logo}"/>

I hope you understand why - if not, please ask.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 4th, 2006, 02:27 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael so how can I also control these optional elements? ($logosource and $logoimage are optional)What should I write to the if statement?

Secondly is it gonna be

<xsl:variable name="logo" select="concat($logosource, '/',$logoimage)"/>

And sorry for the silly question why should I use {} for <img src= "{$logo}"/>?

Your attitude determines your altitude
 
Old September 4th, 2006, 02:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Don't put the variable reference in quotes, otherwise the string "$logosource" will be written to the output.

If $logosource holds an empty sequence then concat() ignores it (treats it as a zero-length string), so you shouldn't need to do anything special for this case - unless of course you want to do something different in this case.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 4th, 2006, 02:58 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thanks very much for your help. Actually with your an the others' help I am becoming a good XSL programmer (it takes a while but I find this forum great)

Your attitude determines your altitude





Similar Threads
Thread Thread Starter Forum Replies Last Post
Optional element exists if has inner elements 2BOrNot2B XML 0 May 9th, 2008 02:11 PM
Inserting into a tree with optional elements iceandrews XSLT 2 April 24th, 2008 08:59 AM
sequenced elements to attributes zkent XSLT 0 April 19th, 2006 08:50 AM
Elements and attributes Morrislgn XSLT 1 June 20th, 2005 11:13 AM
Elements w same name and their attributes supafly XSLT 1 May 30th, 2005 06:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.