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 4th, 2006, 05:17 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I don't have any problem with it now Michael but I cannot see the output of

<a href="{$i}"><xsl:value-of select="$cut"/><xsl:text>...</xsl:text></a>

as an a href link. It shows me that in output as

<td class="text"><h3>Students' Paths To Small Colleges Can Bypass SAT </h3>
instead of
<td class="text"><h3><a href = "0">Students' Paths To Small Colleges Can Bypass SAT </a></h3>

how can I solve this problem?
Actually for the $<=0 control what should I write?



Your attitude determines your altitude
 
Old September 4th, 2006, 07:25 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok my last try

<?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:GetFolderHeadlinesResponse/fcs:folderHeadlinesResponse/fcs:folderHeadlinesResult/fcs:folder/fcs:folderHeadlinesResultSet"></xsl:apply-templates>
</xsl:template>
<xsl:template name="recursion" match="SOAP-ENV:Envelope/SOAP-ENV:Body/fcs:GetFolderHeadlinesResponse/fcs:folderHeadlinesResponse/fcs:folderHeadlinesResult/fcs:folder/fcs:folderHeadlinesResultSet" mode="recurse">
    <xsl:param name="i" select="0"/>
    <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>

        <img src="http://dg1-2.internal.epo.org/_test/Huerol/Factiva/fac1.bmp" align="right" />
        <br clear="all"/>
        <table id="epoNewsItem" style="border-bottom:none">

                <xsl:for-each select="fcs:folderHeadline">
                <xsl:variable name="content" select="fcs:contentParts/@contentType"/>

                <xsl:variable name="year" select="substring(fcs:publicationDate,0,5)"/>
                <xsl:variable name="month" select="substring(fcs:publicationDate,6,2)"/>
                <xsl:variable name="day" select="substring(fcs:publicationDate,9,2)"/>
                <tr>
                     <xsl:choose>
                                        <xsl:when test="$content='WebPage'">
                                            <td class="text"><img src="http://dg1-2.internal.epo.org/_test/Huerol/Factiva/fwebicon.gif" alt="Factiva Web Content Icon" style='margin-top:3px'/><xsl:text></xsl:text><xsl:value-of select="$day"/>.<xsl:value-of select="$month"/>.<xsl:value-of select="$year"/></td>
                                        </xsl:when>
                                        <xsl:otherwise>
                    <td class="text"><img src="http://dg1-2.internal.epo.org/_test/Huerol/Factiva/fac_pub.gif" alt="Factiva Publications Icon" style='margin-top:3px'/><xsl:text></xsl:text><xsl:value-of select="$day"/>.<xsl:value-of select="$month"/>.<xsl:value-of select="$year"/></td>
                    </xsl:otherwise>
                                    </xsl:choose>
                 </tr>
                <tr>
                     <td class="text"><h3>
                    <xsl:variable name="headline" select="fcs:headline/fcs:paragraph"/>
                    <xsl:variable name="cut" select="substring($headline,0,50)"/>
                    <a href="{$i}"><xsl:value-of select="$cut"/></a>
                    <xsl:call-template name="recursion">
                        <xsl:with-param name="i" select="$i+1"/>
                    </xsl:call-template>
                    </h3></td>
                 </tr>
                 <tr>
                     <xsl:variable name="snippet" select="fcs:snippet"/>
                     <xsl:variable name="cPos" select="string-length(substring-before($snippet, '-- '))"/>
                    <xsl:choose>
                        <xsl:when test="$cPos > 0">
                            <xsl:variable name="cutSnippet" select="substring($snippet,$cPos+3,100+$cPos+3)"/>
                            <td class="text"><xsl:value-of select="$cutSnippet"/></td>
                        </xsl:when>
                        <xsl:otherwise>
                         <xsl:variable name="cutSnippet" select="substring($snippet,0,100)"/>
                         <td class="text"><xsl:value-of select="$cutSnippet"/></td>
                        </xsl:otherwise>
                    </xsl:choose>

                 </tr>
                </xsl:for-each>
        </table>
        </body>
    </xsl:template>
            
</xsl:stylesheet>
But when I do an XSLT with test.xml then I get this text

n20060831782688NYTF000020060831e28v0004s13662006-08-31nytfThe New York TimesNational Desk; SECTAStudents' Paths To Small Colleges Can Bypass SAT It is still far too early to sound the death knell, but for many small liberal arts colleges, the SAT may have outlived its usefulness. Since Bowdoin and Bates dropped their testing requirements decades ago, more than a fourth of U.S. News ...By TAMAR LEWIN (c) 2006 New York Times Company 45665568NoneenBLDW000020060831e28v0000z BLDW000020060831e28v0000z4292006-08-31bldwBlood WeeklyHIV/AIDS Anemia; Direct antiglobulin-positive results may be related to lower hemoglobin levels in HIV/AIDS 2006 AUG 31 - (NewsRx.com) -- Direct antiglobulin-positive results may be related to lower hemoglobin levels in HIV-infected patients. "There are conflicting opinions regarding the effect of positive direct antiglobulin test (DAT) on ...(c) Copyright 2006 Blood Weekly via NewsRx.com 45665106Noneen20060831780375NYTF0000 20060831e28v0002b4452006-08-31nytfThe New York TimesEditorial Desk; SECTARaising Nicotine Doses, on the Sly While most of us thought the country was trying to curb smoking, and the rapacious habits of the tobacco companies, it turns out the industry has been sneakily making cigarettes more addictive. (c) 2006 New York Times Company 45664981Noneen20060831780367NYTF0000200 60831e28v0002a4992006-08-31nytfThe New York TimesEditorial Desk; SECTAStars in Their Eyes In a rare moment of candor this week, Defense Secretary Donald Rumsfeld acknowledged that he's not sure if the United States missile defense system is ready to work. When asked if the shield could protect the United States from a North ...(c) 2006 New York Times Company 45664980NoneenBLDW000020060831e28v0000g BLDW000020060831e28v0000g2222006-08-31bldwBlood WeeklyBusiness Update; Hema-Quebec selects IDM Surround as its laboratory management system 2006 AUG 31 - (NewsRx.com) -- Information Data Management, Inc., (IDM) announced that Hema-Quebec has selected IDM's Surround 4.2.1 System as their new centralized data collection and laboratory management system. (c) Copyright 2006 Blood Weekly via NewsRx.com 45665004None

although I have an HTML structure in my XSL why? Can anyone tell me what am I doing wrong?

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

You asked it to output <a href="{$i}">, and $i was zero, so it output <a href="0">. I can't see what else you would have expected it to do.

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

ok Michael I thought you have sent your reply before my last changes. Actually this aplly templte did nothing i have tried to write other sample things like Hallo World with p but it didn^t show anything.

When I try to write it in a seperate template and reference it with apply templates it doesn't recognize my parameter and when I define this parameter in that template and call it again then it is of course zero.

I tried to define the parameter and call it in the template with the name "recursive" but this time it gives me the every info that it has under fcs:headline. I am completely clueless. If you want to try to see the result you can see the XML file of test.xsl at the first page.

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

You have posted within five minutes of receiving my latest reply.

I don't think you are making a serious effort to solve your own problems before posting. I'm not here to do your debugging for you - please don't post questions until you have made a serious attempt to solve the problems yourself.

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

I am making a serious effort to solve my problem for hours Michael. You can be sure of it. My poroblem is now

    <xsl:variable name="headline" select="fcs:headline/fcs:paragraph"/>
                    <xsl:variable name="cut" select="substring($headline,0,50)"/>
                    <a href="{$i}"><xsl:value-of select="$cut"/></a>
                    <xsl:call-template name="recursion">
                        <xsl:with-param name="i" select="$i+1"/>
                    </xsl:call-template>
that it doesn't print out the values in HTML form but in text form allthough I embedded it in HTML tags and if you see the code above I have given the name recursion to the main template to call this recursive template. It calls it for sure and I am seeing the output but not as I desired to have it. It was my fault before to put the all stuff in another seperate template and to define the parameter in this template. It has always taken the parameter value as 0. Now it is defined in the main template where I defined the all stylesheet and HTML values but it gives me a text result instead of an HTML tagged result.

Your attitude determines your altitude
 
Old September 4th, 2006, 09:00 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the error:
Either I write and reference the recursive template or not and either I put the parameter value in a href or not, when I write <xsl:template name="recursion" match="SOAP-ENV:Envelope/SOAP-ENV:Body/fcs:GetFolderHeadlinesResponse/fcs:folderHeadlinesResponse/fcs:folderHeadlinesResult/fcs:folder/fcs:folderHeadlinesResultSet" it turns everything into the text format and I don't know why. I am really stuck now.

Your attitude determines your altitude
 
Old September 4th, 2006, 10:59 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok I am doing it again from scratch. I designed a new example its xml source is

<?xml version="1.0" encoding="UTF-8"?>
<links xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="X:\Private\Factiva\ testlink.xsd">
    <name>link1</name>
    <value>1</value>
    <name>link2</name>
    <value>2</value>
</links>
Its xsl is like this
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
<xsl:output method="html" version="4.0"/>
<xsl:template name="link" match="/">
<xsl:param name="id" select="0"/>
<xsl:for-each select="/name">
<html>
    <head>
        <title></title>
    </head>
    <body>
    <a href="{$id}"><xsl:value-of select="name"/></a>

    </body>
</html>
<xsl:call-template name="link">
 <xsl:with-param name="id" select="$id+1"/>
</xsl:call-template>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

My output is:

link11 link22
and allthough I wanted the output as HTML, I have become it as text without two links why?

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

In my testing your stylesheet produces no output at all. That's because it's only template rule does:

<xsl:for-each select="/name"

which processes all "name" elements that are immediate children of the root (document) node, and there aren't any (the only immediate child of the document node is called "links").

Your output was the textual content of the source XML, which is what you get if the stylesheet has no matching template rules at all. If that's what you got, there must have been another error, perhaps you weren't invoking this stylesheet but a different one.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 4th, 2006, 11:37 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, I've completely lost the thread of what your are struggling with. This stylesheet processes the simple links file you have above:
Code:
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
    <html>
    <body>
      <xsl:apply-templates select="links/name" />
    </body>
    </html>
</xsl:template>

  <xsl:template match="name">
    Position: <xsl:value-of select="position()"/><br/>
    Name: <xsl:value-of select="."/><br/>
    Value: <xsl:value-of select="following-sibling::value[1]"/><br/>
  </xsl:template>
</xsl:stylesheet>
--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to loop through a HashMap in XSL? sunilnk XSLT 6 April 10th, 2017 04:09 AM
help: how can I break from xsl for-each loop ? back2grave XSLT 5 May 31st, 2012 12:03 PM
XSL Loop and incrementing a variable 2007-03-29 XSLT 8 March 30th, 2007 10:41 AM
xsl:for-each loop Tomi XSLT 3 September 7th, 2006 05:35 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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