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 May 7th, 2008, 12:19 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Contains function call not working correctly

I would like the xslt to display the first three Webcast nodes in my xml file that have a ProductType attribute equal to 'Video'. The code I'm currently using runs into a problem when i use an <xsl:when> to test if ProductType contains the appropriate string. This never is true, even though there are defintely nodes that fit this classification in the xml.

Here is the offending xslt:

  <xsl:template name="itemIncrement">
    <xsl:param name="increment" select="1"/>
    <xsl:param name="max" select="1"/>
    <xsl:param name="timesLooped" select="1"/>
    <xsl:value-of select="$timesLooped"/>:
    <xsl:if test="$increment &lt;= $max and $timesLooped &lt;= count($webcastsxml//Webcast)">
      <xsl:variable name="currentWebcastNode" select="$webcastsxml//Webcast[$timesLooped]"/>
      <xsl:variable name="productType" select="$currentWebcastNode/@ProductType"/>
      <xsl:variable name="productID" select="$currentWebcastNode/@ID"/>

      <xsl:choose>
        <xsl:when test="contains($productType, 'Video')">

          <br/>
          --------------------------------------------
          <br/>
          A VIDEO!: <xsl:value-of select="$productID"/>, <xsl:value-of select="$productType"/>
          <xsl:call-template name="Webcast">
            <xsl:with-param name="currentNode" select="$productType"/>
          </xsl:call-template>
          <xsl:call-template name="itemIncrement">
            <xsl:with-param name="max" select="$max"/>
            <xsl:with-param name="increment" select="$increment + 1"/>
            <xsl:with-param name="timesLooped" select="$timesLooped + 1"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="itemIncrement">
            <xsl:with-param name="max" select="$max"/>
            <xsl:with-param name="increment" select="$increment"/>
            <xsl:with-param name="timesLooped" select="$timesLooped + 1"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

I'm using MSXML 4, and I believe we're using Windows Server 2003 as the OS.

Thanks
 
Old May 7th, 2008, 12:29 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Try to post a minimal but complete XML input document and syylesheet that allows us to reproduce the problem.
If you believe that MSXML 4 is the culprit then test with other XSLT 1.0 processors like Saxon 6.5 or Xalan, that should allow you to find out whether the problem is with your stylesheet or with your XSLT processor.


--
  Martin Honnen
  Microsoft MVP - XML
 
Old May 7th, 2008, 12:41 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here are a couple of Event nodes from the xml file (out of around 20 similar). They're all children of the Events node. Their Webcast subnodes can have ProductType attributes of several different values, or none at all.

I am pretty new to xslt programming. Could you suggest an efficient way to test with the various xslt processors? Thanks for the help.

<?xml version="1.0" standalone="no" ?>
<IRXML CorpMasterID="xxxxxx">
<Events PubDate="20080507" PubTime="10:39:51" CorpMasterID="xxxxxx">
<Event EventID="912672" EventType="1" ParentEventID="912671" EventDateEstimate="No" DLU="Mar 5 2005 1:02PM" EventStatus="10" AllowCalendarToDetailsDrilldown="Yes" TimeZone="GMT" EventStartDate="20110507" EventStartTime="02:00:00" EventEndDate="20110507" EventEndTime="" EventDisplayFromDate="20050305" EventDisplayFromTime="18:02:15" EventDisplayToDate="20210506" EventDisplayToTime="23:59:59" MultiDay="No" DetailsPageTitle="Event Details" DisplayWithParent="Yes" TickerSymbol="" CompanyName="CCBN Xml Sample">
  <EventTitle>Q2 2011 Sample XML Earnings Conference Call</EventTitle>
- <DisplayableDatesTimes>
  <DisplayableDateTime TimeZone="ET" EventStartDate="20110506" EventStartTime="22:00:00" EventEndDate="" EventEndTime="" MultiDay="No" SpecialLabel="" />
  </DisplayableDatesTimes>
  <EventDuration Hours="1" />
  <DrillDownOverridingLinkUrl Stream="No" />
  <EventEmailReminder DaysPrior="2" />
  <Description />
  <FutureEvents Title="Future Events">To be notified by e-mail of future events such as quarterly conference calls and other investor meetings, please subscribe to the e-mail alert list located on our <A HREF="ir_site.zhtml?ticker=***XML&script=1000">Cal endar Page</A>.</FutureEvents>
  <AdditionalInformationContact />
- <Webcasts DisplayLinkToAudioArchives="No" DisplayFormats="Yes" SectionTitle="Webcast Presentations">
  <WebcastDisplayFormatsText>(Download Plug-In and Perform Webcast System Compatibility Tests)</WebcastDisplayFormatsText>
  <WebcastIconURL>http://media.corporate-ir.net/media_files/templates/webcast/microphone_small.gif</WebcastIconURL>
  <WebcastDisclaimer Display="Yes">Unauthorized recording or downloading of this event is not permitted.<BR><BR><IMG src="http://www.corporate-ir.net/media_files/templates/webcast/logo_thomson_ed.gif" alt="Thomson.com" border="0" align="center"><BR> © Copyright 2004 by Thomson Financial, Inc. All Rights Reserved.</WebcastDisclaimer>
- <Webcast ID="363082" ProductType="Enhanced Audio">
- <Streams>
- <Stream ID="418699" RegistrationRequired="Yes" DisplayFromDate="20050305" DisplayFromTime="18:02:15" DisplayToDate="20210507" DisplayToTime="23:59:59" TimeZone="GMT" DisplayOrder="1" Type="Enhanced Audio">
  <StreamDescription>Click here for webcast</StreamDescription>
  <URL Stream="Yes">http://web.servicebureau.net/conf/meta?i=1112469121&c=2343&m=was&u=/w_ccbn.xsl&date_ticker=5_6_2011_***XML</URL>
- <Encodings>
- <Encoding>
  <EncodingCodec>Windows</EncodingCodec>
  <EncodingIconUrl>http://www.corporate-ir.net/media_files/priv/ccbn/event_help/icons/winmedia.gif</EncodingIconUrl>
  <EncodingSoftwareUrl>http://www.corporate-ir.net/media_files/priv/ccbn/event_help/webcasthelp/index.htm#Webcast_Players.htm</EncodingSoftwareUrl>
  <EncodingDescription>Windows Media</EncodingDescription>
  </Encoding>
  </Encodings>
  </Stream>
  </Streams>
  </Webcast>
  </Webcasts>
  </Event>
- <Event EventID="918110" EventType="7" ParentEventID="918106" EventDateEstimate="No" DLU="Jul 14 2004 9:00AM" EventStatus="11" AllowCalendarToDetailsDrilldown="No" TimeZone="GMT" EventStartDate="20040801" EventStartTime="" EventEndDate="20040801" EventEndTime="" EventDisplayFromDate="20040714" EventDisplayFromTime="13:00:17" EventDisplayToDate="20140801" EventDisplayToTime="23:59:59" MultiDay="No" DetailsPageTitle="Event Details" DisplayWithParent="No" TickerSymbol="" CompanyName="CCBN Xml Sample">
  <EventTitle>Sample XML at StreetEvents.com Conference</EventTitle>
- <DisplayableDatesTimes>
  <DisplayableDateTime TimeZone="" EventStartDate="20040801" EventStartTime="" EventEndDate="" EventEndTime="" MultiDay="No" SpecialLabel="NST" />
  </DisplayableDatesTimes>
  <DrillDownOverridingLinkUrl Stream="No" />
  <EventEmailReminder DaysPrior="2" />
  <Description />
  <FutureEvents Title="Future Events">To be notified by e-mail of future events such as quarterly conference calls and other investor meetings, please subscribe to the e-mail alert list located on our <A HREF="ir_site.zhtml?ticker=***XML&script=1000">Cal endar Page</A>.</FutureEvents>
  <AdditionalInformationContact />
  ID="718818">
- <Webcasts DisplayLinkToAudioArchives="No" DisplayFormats="Yes" SectionTitle="Webcast Presentations">
  <WebcastDisplayFormatsText>(Download Plug-In and Perform Webcast System Compatibility Tests)</WebcastDisplayFormatsText>
  <WebcastIconURL>http://media.corporate-ir.net/media_files/templates/webcast/microphone_small.gif</WebcastIconURL>
  <WebcastDisclaimer Display="Yes">Unauthorized recording or downloading of this event is not permitted.<BR><BR><IMG src="http://www.corporate-ir.net/media_files/templates/webcast/logo_thomson_ed.gif" alt="Thomson.com" border="0" align="center"><BR> © Copyright 2004 by Thomson Financial, Inc. All Rights Reserved.</WebcastDisclaimer>
- <Webcast ID="367453" ProductType="Video">
- <Streams>
- <Stream ID="423916" RegistrationRequired="Yes" DisplayFromDate="20040714" DisplayFromTime="13:00:17" DisplayToDate="20140801" DisplayToTime="23:59:59" TimeZone="GMT" DisplayOrder="1" Type="Basic Audio">
  <StreamDescription>Click here for webcast</StreamDescription>
  <LinkWindowMinHeight>480</LinkWindowMinHeight>
  <LinkWindowMinWidth>360</LinkWindowMinWidth>
  <LinkWindowTarget>_new</LinkWindowTarget>
  <URL />
- <Encodings>
- <Encoding>
  <EncodingCodec>28.8</EncodingCodec>
  <EncodingIconUrl>http://www.corporate-ir.net/media_files/priv/CCBN/event_help/icons/realplayer.gif</EncodingIconUrl>
  <EncodingSoftwareUrl>http://www.corporate-ir.net/media_files/priv/ccbn/event_help/webcasthelp/index.htm#Webcast_Players.htm</EncodingSoftwareUrl>
  <EncodingDescription>Real Media</EncodingDescription>
  </Encoding>
  </Encodings>
  </Stream>
- <Stream ID="423917" RegistrationRequired="Yes" DisplayFromDate="20040714" DisplayFromTime="13:00:17" DisplayToDate="20140801" DisplayToTime="23:59:59" TimeZone="GMT" DisplayOrder="2" Type="Video">
  <StreamDescription>Click here for webcast</StreamDescription>
  <LinkWindowMinHeight>480</LinkWindowMinHeight>
  <LinkWindowMinWidth>360</LinkWindowMinWidth>
  <LinkWindowTarget>_new</LinkWindowTarget>
  <URL />
- <Encodings>
- <Encoding>
  <EncodingCodec>Windows</EncodingCodec>
  <EncodingIconUrl>http://www.corporate-ir.net/media_files/priv/ccbn/event_help/icons/winmedia.gif</EncodingIconUrl>
  <EncodingSoftwareUrl>http://www.corporate-ir.net/media_files/priv/ccbn/event_help/webcasthelp/index.htm#Webcast_Players.htm</EncodingSoftwareUrl>
  <EncodingDescription>Windows Media</EncodingDescription>
  </Encoding>
  </Encodings>
- <Encodings>
- <Encoding>
  <EncodingCodec>28.8</EncodingCodec>
  <EncodingIconUrl>http://www.corporate-ir.net/media_files/priv/CCBN/event_help/icons/realplayer.gif</EncodingIconUrl>
  <EncodingSoftwareUrl>http://www.corporate-ir.net/media_files/priv/ccbn/event_help/webcasthelp/index.htm#Webcast_Players.htm</EncodingSoftwareUrl>
  <EncodingDescription>Real Media</EncodingDescription>
  </Encoding>
  </Encodings>
  </Stream>
  </Streams>
  </Webcast>
  </Webcasts>
  </Event>
  </Events>
  </IRXML>
 
Old May 7th, 2008, 12:49 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Saxon 6.5 and Xalan are Java applications so you can run them from the command line with the java command, if you have a Java runtime installed. But they are just examples of XSLT 1.0 processors, there are others.
Various XML editors might also allow you to configure them to test with different XSLT processors.

As for your sample, we will need to see the XSLT as well and an explanation of what it is supposed to to.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old May 7th, 2008, 01:00 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, here is the xslt. Right now, all the transformation should do is select the first three //Webcast nodes with an attribute ProductType that is equal to 'Video'. It should call the Webcast template every time this condition is met, which displays a bit of info about the node and lets me know the Webcast template was called.

I'm getting the xml data through a cms, which is how the webcastsxml variable gets its data.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:media="http://search.yahoo.com/mrss"
exclude-result-prefixes="msxml umbraco.library media">

  <xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:variable name="url" select="/macro/url" />
  <xsl:variable name="webcastsxml" select="umbraco.library:GetXmlDocument($url,0)" />

  <xsl:template name="itemIncrement">
    <xsl:param name="increment" select="1"/>
    <xsl:param name="max" select="1"/>
    <xsl:param name="timesLooped" select="1"/>
    <xsl:value-of select="$timesLooped"/>:
    <xsl:if test="$increment &lt;= $max and $timesLooped &lt;= count($webcastsxml//Webcast)">
      <xsl:variable name="currentWebcastNode" select="$webcastsxml//Webcast[$timesLooped]"/>
      <xsl:variable name="productType" select="$currentWebcastNode/@ProductType"/>
      <xsl:variable name="productID" select="$currentWebcastNode/@ID"/>

      <xsl:choose>
        <xsl:when test="contains($productType, 'Video')">

          <br/>
          --------------------------------------------
          <br/>
          A VIDEO!: <xsl:value-of select="$productID"/>, <xsl:value-of select="$productType"/>
          <xsl:call-template name="Webcast">
            <xsl:with-param name="currentNode" select="$productType"/>
          </xsl:call-template>
          <xsl:call-template name="itemIncrement">
            <xsl:with-param name="max" select="$max"/>
            <xsl:with-param name="increment" select="$increment + 1"/>
            <xsl:with-param name="timesLooped" select="$timesLooped + 1"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="itemIncrement">
            <xsl:with-param name="max" select="$max"/>
            <xsl:with-param name="increment" select="$increment"/>
            <xsl:with-param name="timesLooped" select="$timesLooped + 1"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

  <xsl:template match="/">
    <xsl:if test="$url != ''">
      <br/>
           <img width="129" height="16" class="recentWebcastsHeader" alt="recentWebcastsTitle" src="/media/2748/recent_webcasts.jpg"/>
           <img width="103" height="30" title="Subscribe for Reminders" class="calendarImg" alt="calendarImage" src="/media/2769/subscribe_btn.jpg"/>
      <br/>
      <br/>
        <xsl:call-template name="itemIncrement">
          <xsl:with-param name="max" select="3"/>
          <xsl:with-param name="increment" select="1"/>
          <xsl:with-param name="timesLooped" select="1"/>
        </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name="Webcast">
    <xsl:param name="currentNode" select="1"/>
      <xsl:value-of select="$currentNode"/>
<br/>
    <p>The Webcast Template</p>
  </xsl:template>
</xsl:stylesheet>
 
Old May 7th, 2008, 01:48 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Upon further examination, it looks like this line is the problem:

<xsl:variable name="currentWebcastNode" select="$webcastsxml//Webcast[$timesLooped]"/>

I want this variable to contain the currently selected Webcast node, based on the number of times looped. However, the only time this variable contains anything is when $timesLooped=1, and in this instance it doesn't even contain the correct Webcast value for that node. This must be a misunderstanding on my part of the XPath statement above. Could somebody explain what changes I should make to get the desired behavior?
 
Old May 7th, 2008, 05:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's a bit difficult to tell because your XML is not nicely formatted, but I suspect that

$webcastsxml//Webcast[$timesLooped]

should be

($webcastsxml//Webcast)[$timesLooped]

The first expression selects every descendant Webcast that is the $timesLooped'th child of its parent; the second selects the $timesLooped'th descendant of $swebcastsxml.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 8th, 2008, 07:53 AM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, that was the problem. Thank you for the advice!





Similar Threads
Thread Thread Starter Forum Replies Last Post
TheBeerhouse Project working correctly in VS 2008 asp125 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 October 10th, 2008 12:33 PM
Hello User, not working correctly? Neotriple BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 October 5th, 2006 11:39 AM
Proxxy Connections working, but not correctly??? ramangill VB.NET 0 August 10th, 2005 06:54 AM
Proxxy Connections working, but not correctly??? ramangill Oracle 0 August 10th, 2005 06:53 AM
No error but not working correctly! Adam H-W Javascript 7 November 10th, 2003 09:34 AM





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