Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 1st, 2006, 10:17 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
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
Reply With Quote
  #2 (permalink)  
Old September 2nd, 2006, 01:08 PM
mhkay's Avatar
Wrox Author
Points: 18,280, Level: 58
Points: 18,280, Level: 58 Points: 18,280, Level: 58 Points: 18,280, Level: 58
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,934
Thanks: 0
Thanked 282 Times in 277 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
Reply With Quote
  #3 (permalink)  
Old September 2nd, 2006, 01:09 PM
mhkay's Avatar
Wrox Author
Points: 18,280, Level: 58
Points: 18,280, Level: 58 Points: 18,280, Level: 58 Points: 18,280, Level: 58
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,934
Thanks: 0
Thanked 282 Times in 277 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
Reply With Quote
  #4 (permalink)  
Old September 4th, 2006, 03:27 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
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
Reply With Quote
  #5 (permalink)  
Old September 4th, 2006, 03:47 AM
mhkay's Avatar
Wrox Author
Points: 18,280, Level: 58
Points: 18,280, Level: 58 Points: 18,280, Level: 58 Points: 18,280, Level: 58
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,934
Thanks: 0
Thanked 282 Times in 277 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
Reply With Quote
  #6 (permalink)  
Old September 4th, 2006, 03:58 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 10:35 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.