XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Jana SilveySubject: Help generating text output
Author: Jana Silvey
Date: 23 Aug 2005 10:53 PM
I am trying to generate text that I can copy and paste into an ASF in Unidata. I can get this xslt to work, until I add the xsl:if test="position()=1">, if I comment out that, it works...something is wrong with the position() part of my code...can someone help me? I am only wanting to put the first instance of the sorted date into the variable for myDate, then call that variable each time it steps through the seminar so that the same value is outputted each time.

xml:
<?xml version="1.0" encoding="UTF-8" ?>
<seminars>
<dnis>
6660
<cust_code>NGCI1</cust_code>
<billing_driver>NGCI1</billing_driver>
<ad_source>RADIO2</ad_source>
<media>RD</media>
<city_code>MGM</city_code>
</dnis>
- <groups>
- <seminar id="c3818479-16e4-45ce-9879-bd5602b09587">
<dnis>6660</dnis>
<description>Quality Inn and Suites at the Governors House</description>
<site_address>2705 E. South Blvd</site_address>
<site_directions>On E. South Blvd., between McGhee Rd. and I-85</site_directions>
<site_city_state>MONTGOMERY, AL</site_city_state>
<site_zip>36116</site_zip>
<site_phone>334-288-2800</site_phone>
<seminar_date_time sort="20050821090000" display="8/21/2005 09:00:00 AM">2005-08-21 09:00:00</seminar_date_time>
<opening_date>1/1/1900 12:00:00 AM</opening_date>
<web_partner>http://mappoint.msn.com</web_partner>
<long_description>MONTGOMERY, AL, Sun, Aug 21 09:00 AM</long_description>
<long_time>Sun, Aug 21 09:00 AM</long_time>
<attendee_name />
<attendee_count>0</attendee_count>
<is_full>False</is_full>
<ad_market />
<market_code>MGM</market_code>
<group_name>MONTGOMERY, AL</group_name>
<start_date>8/3/2005 12:00:00 AM</start_date>
<end_name>8/23/2005 12:00:00 AM</end_name>
<tour_code>MGM082105A</tour_code>
<site_code>MGM082105A</site_code>
<market_tour_code>MGM082105A</market_tour_code>
<time>09:00 AM</time>
<date>Sun, Aug 21</date>
</seminar>
- <seminar id="ef6263f2-4b83-4aba-9b15-c3229580882b">
<dnis>6660</dnis>
<description>Embassy Suites Montgomery</description>
<site_address>300 Tallapoosa Street</site_address>
<site_directions>Adjacent to the Montgomery Civic Center</site_directions>
<site_city_state>MONTGOMERY, AL</site_city_state>
<site_zip>36104</site_zip>
<site_phone>334-269-5055</site_phone>
<seminar_date_time sort="20050820150000" display="8/20/2005 03:00:00 PM">2005-08-20 15:00:00</seminar_date_time>
<opening_date>1/1/1900 12:00:00 AM</opening_date>
<web_partner>http://mappoint.msn.com</web_partner>
<long_description>MONTGOMERY, AL, Sat, Aug 20 03:00 PM</long_description>
<long_time>Sat, Aug 20 03:00 PM</long_time>
<attendee_name />
<attendee_count>0</attendee_count>
<is_full>False</is_full>
<ad_market />
<market_code>MGM</market_code>
<group_name>MONTGOMERY, AL</group_name>
<start_date>8/3/2005 12:00:00 AM</start_date>
<end_name>8/23/2005 12:00:00 AM</end_name>
<tour_code>MGM082005B</tour_code>
<site_code>MGM082005B</site_code>
<market_tour_code>MGM082005B</market_tour_code>
<time>03:00 PM</time>
<date>Sat, Aug 20</date>
</seminar>
- <seminar id="6fdff614-4078-4367-a14f-123e4b3ea3a0">
<dnis>6660</dnis>
<description>Quality Inn and Suites at the Governors House</description>
<site_address>2705 E. South Blvd</site_address>
<site_directions>On E. South Blvd., between McGhee Rd. and I-85</site_directions>
<site_city_state>MONTGOMERY, AL</site_city_state>
<site_zip>36116</site_zip>
<site_phone>334-288-2800</site_phone>
<seminar_date_time sort="20050821150000" display="8/21/2005 03:00:00 PM">2005-08-21 15:00:00</seminar_date_time>
<opening_date>1/1/1900 12:00:00 AM</opening_date>
<web_partner>http://mappoint.msn.com</web_partner>
<long_description>MONTGOMERY, AL, Sun, Aug 21 03:00 PM</long_description>
<long_time>Sun, Aug 21 03:00 PM</long_time>
<attendee_name />
<attendee_count>0</attendee_count>
<is_full>False</is_full>
<ad_market />
<market_code>MGM</market_code>
<group_name>MONTGOMERY, AL</group_name>
<start_date>8/3/2005 12:00:00 AM</start_date>
<end_name>8/23/2005 12:00:00 AM</end_name>
<tour_code>MGM082105B</tour_code>
<site_code>MGM082105B</site_code>
<market_tour_code>MGM082105B</market_tour_code>
<time>03:00 PM</time>
<date>Sun, Aug 21</date>
</seminar>
- <seminar id="150c83f5-bd92-48cc-89c8-543cd0f53c25">
<dnis>6660</dnis>
<description>Dothan Conference Center</description>
<site_address>3113 Oxmoor Industrial Blvd.</site_address>
<site_directions>Hwy. 231 N. to Naperfield Rd. exit, follow signs</site_directions>
<site_city_state>DOTHAN, AL</site_city_state>
<site_zip>36303</site_zip>
<site_phone>334-983-8720</site_phone>
<seminar_date_time sort="20050822190000" display="8/22/2005 07:00:00 PM">2005-08-22 19:00:00</seminar_date_time>
<opening_date>1/1/1900 12:00:00 AM</opening_date>
<web_partner>http://mappoint.msn.com</web_partner>
<long_description>DOTHAN, AL, Mon, Aug 22 07:00 PM</long_description>
<long_time>Mon, Aug 22 07:00 PM</long_time>
<attendee_name />
<attendee_count>0</attendee_count>
<is_full>False</is_full>
<ad_market />
<market_code>MGM</market_code>
<group_name>MONTGOMERY, AL</group_name>
<start_date>8/3/2005 12:00:00 AM</start_date>
<end_name>8/23/2005 12:00:00 AM</end_name>
<tour_code>MGM082205B</tour_code>
<site_code>DHN082205B</site_code>
<market_tour_code>MGM082205B</market_tour_code>
<time>07:00 PM</time>
<date>Mon, Aug 22</date>
</seminar>
- <seminar id="c94f4637-a833-48b0-9812-60c9c445303f">
<dnis>6660</dnis>
<description>Dothan Conference Center</description>
<site_address>3113 Oxmoor Industrial Blvd.</site_address>
<site_directions>Hwy. 231 N. to Naperfield Rd. exit, follow signs</site_directions>
<site_city_state>DOTHAN, AL</site_city_state>
<site_zip>36303</site_zip>
<site_phone>334-983-8720</site_phone>
<seminar_date_time sort="20050822130000" display="8/22/2005 01:00:00 PM">2005-08-22 13:00:00</seminar_date_time>
<opening_date>1/1/1900 12:00:00 AM</opening_date>
<web_partner>http://mappoint.msn.com</web_partner>
<long_description>DOTHAN, AL, Mon, Aug 22 01:00 PM</long_description>
<long_time>Mon, Aug 22 01:00 PM</long_time>
<attendee_name />
<attendee_count>0</attendee_count>
<is_full>False</is_full>
<ad_market />
<market_code>MGM</market_code>
<group_name>MONTGOMERY, AL</group_name>
<start_date>8/3/2005 12:00:00 AM</start_date>
<end_name>8/23/2005 12:00:00 AM</end_name>
<tour_code>MGM082205A</tour_code>
<site_code>DHN082205A</site_code>
<market_tour_code>MGM082205A</market_tour_code>
<time>01:00 PM</time>
<date>Mon, Aug 22</date>
</seminar>
- <seminar id="9afb4f7c-ac98-42cf-8683-63fd04b36e27">
<dnis>6660</dnis>
<description>Embassy Suites Montgomery</description>
<site_address>300 Tallapoosa Street</site_address>
<site_directions>Adjacent to the Montgomery Civic Center</site_directions>
<site_city_state>MONTGOMERY, AL</site_city_state>
<site_zip>36104</site_zip>
<site_phone>334-269-5055</site_phone>
<seminar_date_time sort="20050820090000" display="8/20/2005 09:00:00 AM">2005-08-20 09:00:00</seminar_date_time>
<opening_date>1/1/1900 12:00:00 AM</opening_date>
<web_partner>http://mappoint.msn.com</web_partner>
<long_description>MONTGOMERY, AL, Sat, Aug 20 09:00 AM</long_description>
<long_time>Sat, Aug 20 09:00 AM</long_time>
<attendee_name />
<attendee_count>0</attendee_count>
<is_full>False</is_full>
<ad_market />
<market_code>MGM</market_code>
<group_name>MONTGOMERY, AL</group_name>
<start_date>8/3/2005 12:00:00 AM</start_date>
<end_name>8/23/2005 12:00:00 AM</end_name>
<tour_code>MGM082005A</tour_code>
<site_code>MGM082005A</site_code>
<market_tour_code>MGM082005A</market_tour_code>
<time>09:00 AM</time>
<date>Sat, Aug 20</date>
</seminar>
</groups>
</seminars>

xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:callFunction="http://www.contoso.com">
<xsl:output method="text"/>
<msxsl:script language="javascript" implements-prefix="callFunction">
<![CDATA[

function ltrim(x){
while (true)
{
if (x.substring(0, 1) != " ")
break;
x = x.substring(1, x.length);
}
return x;
}

function rtrim(y) {
while (true) {
if (y.substring(y.length - 1, y.length) != " ")
break;
y = y.substring(0, y.length - 1);
}
return y;
}

function trim(x) {
var tmpstr = ltrim(x);
x = rtrim(tmpstr);
return x;
}


function noReturns1(x) {
while (true) {
if (x.substring(0, 1) != "\n")
break;
x = x.replace("\n", " ");
}
return x;
}

function noReturns2(x) {
while (true) {
if (x.substring(x.length - 1, x.length) != "\n")
break;
x = x.replace("\n", " ");
}
return x;
}

function cleanData(x) {
var tmpstr = trim(x);
x = noReturns1(tmpstr);
x = noReturns2(x);
x = trim(x);
return x;
}
]]>
</msxsl:script>

<xsl:template match="/">

<xsl:variable name="tilde" select="'~'"/>
<xsl:variable name="return" select="'&#13;'"/>

<xsl:for-each select="//seminar">

<xsl:sort select="seminar_date_time" order="ascending" data-type="text"/>
<xsl:if test="position()=1">
<xsl:variable name="myDate" select="seminar_date_time/@display"/>
</xsl:if>

<xsl:value-of select="callFunction:cleanData(string(description))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_address))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_directions))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_city_state))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_phone))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(substring-after(long_time,', ')))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_code))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(market_code))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(substring-before(seminar_date_time/@display,' ')))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(tour_code))"/>
<xsl:value-of select="$tilde"/>

<xsl:value-of select="callFunction:cleanData(string(substring-before($myDate,' ')))"/>


<xsl:value-of select="$tilde"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_zip))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(substring-before(group_name,',')))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(web_partner))"/>
<xsl:value-of select="$return"/>

</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Posttop
Jana SilveySubject: Help generating text output
Author: Jana Silvey
Date: 24 Aug 2005 11:10 AM
I found my answer, I just need to know the all the stupid rules before I try things! I keep being told that XSLT is my "friend", it can do anything I want it to, I know it is user error, but it still frustrates me when I think something is logical, but goes against the rules...lol.

I had to remove the if and variable assignment from the for-each and created a variable that is assigned an xml with the if and assigment in it.

Here is what I did:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:callFunction="http://www.contoso.com" >
<xsl:output method="text"/>
<msxsl:script language="javascript" implements-prefix="callFunction">
<![CDATA[

function ltrim(x){
while (true)
{
if (x.substring(0, 1) != " ")
break;
x = x.substring(1, x.length);
}
return x;

function rtrim(y) {
while (true) {
if (y.substring(y.length - 1, y.length) != " ")
break;
y = y.substring(0, y.length - 1);
}
return y;
}

function trim(x) {
var tmpstr = ltrim(x);
x = rtrim(tmpstr);
return x;
}

function noReturns1(x) {
while (true) {
if (x.substring(0, 1) != "\n")
break;
x = x.replace("\n", " ");
}
return x;
}

function noReturns2(x) {
while (true) {
if (x.substring(x.length - 1, x.length) != "\n")
break;
x = x.replace("\n", " ");
}
return x;
}

function cleanData(x) {
var tmpstr = trim(x);
x = noReturns1(tmpstr);
x = noReturns2(x);
x = trim(x);
return x;
}
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:variable name="tilde" select="'~'"/>
<xsl:variable name="return" select="'&#13;'"/>
<xsl:variable name="first_date">
<root>
<start_date>
<xsl:for-each select="//seminar">
<xsl:sort select="seminar_date_time" order="ascending" data-type="text"/>
<xsl:if test="position()=1">
<xsl:value-of select="seminar_date_time/@display"/>
</xsl:if>
</xsl:for-each>
</start_date>
</root>
</xsl:variable>

<xsl:for-each select="//seminar">
<xsl:sort select="seminar_date_time" order="ascending" data-type="text"/>

<xsl:value-of select="callFunction:cleanData(string(description))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_address))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_directions))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_city_state))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_phone))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(substring-after(long_time,', ')))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_code))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(market_code))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(substring-before(seminar_date_time/@display,' ')))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(tour_code))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(substring-before(msxsl:node-set($first_date)//start_date,' ')))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(site_zip))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(substring-before(group_name,',')))"/>
<xsl:value-of select="$tilde"/>
<xsl:value-of select="callFunction:cleanData(string(web_partner))"/>
<xsl:value-of select="$return"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.