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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> - XSL-fo and how to line feed th... (1)
-> + Houston we have a problem (2)
-> + XSL-FO PDF generation (2)
-> + StylusStudio - pick XSLT 1.0 b... (6)
-> - Stylus Studio 2010 debugging f... (1)
-> - Drop down menu List / Option M... (1)
-> - XML transformation using Java ... (1)
-> + i can't to find XSLT editor in... (2)
-> - Copy xml input as value of an ... (1)
-> - Remove Name space from the Tab... (1)
-> - CGI formatted URL with name/va... (1)
-> - Problem with counting (1)
-> + for-each loop is only returnin... (3)
-> - sort date but some dates may b... (1)
-> - Entity Conversion (1)
-> - How can I build an xml convert... (1)
-> + Little Help (2)
-> + how do I merge nodes to one sc... (2)
-> - beginner help xslt and xpath (1)
-> - Convert XML Feed to CSV/SQL/XL... (1)
-> - Working with text node. (1)
-> - No Topic (1)
-> - API for XSLT Converter for .NE... (1)
-> - Getting started (1)
-> + saxon sql extensions - mysql a... (2)
-> - How do I copy and create new e... (1)
-> + substring-before and sums (3)
-> + Parsing special characters in ... (2)
-> + Schema - Require attribute in ... (2)
-> - Edit existing XSL files when n... (1)
-> + How can I use one single XSLT ... (2)
-> - Default selection of value in ... (1)
-> - Problem with watermark in pdf ... (1)
-> + XSLT Parameter Values dialog n... (3)
-> + Value of File Name is not acce... (10)
-> - Need help with a complex table... (1)
-> - How to replace all nordic char... (1)
-> - XSLT java heap space error wit... (1)
-> - Table Overflow to next page (1)
-> - Using XSLT 2.0 to define custo... (1)
-> - "standalone" attribute and xs... (1)
-> + Standardizing IP addresses (2)
-> + Programmatically changing page... (6)
-> + Can Stylus generate XSLT if so... (5)
-> + Extraction based on NODE Name. (2)
-> + NO XSLT:WYSIWYG (2)
-> + determine condition at run tim... (2)
-> - How to reduce top margin in ev... (1)
-> + need help on xsl looping (4)
-> - Convert Symbol to Element (1)
-> + Separator -only- between field... (3)
-> + DocBook (9)
-> + First Occurance of Alphabet (2)
-> + XSL:Key and Document (2)
-> + Excel Macro using XSLT (2)
-> + Add missing element and attrib... (2)
-> + XSL: Stop Count at First Match (2)
-> + XSD to EDI (4)
-> + How to access data from nested... (2)
-> + Simple division of XML file (2)
-> - XML to Flat File (1)
-> + Dispalying data whith xsl:for ... (3)
-> - distinct nodes - into 3 column... (1)
-> + Newbie at XML (2)
-> + XSL Not Working (3)
-> + to draw table using xsl (2)
-> + Base64 decoder (5)
-> + How to create a hidden sheet u... (3)
-> + XML Reports (2)
-> + Copying image files from one d... (2)
-> + XML conversion to RSS (2)
-> + Inserting Image (2)
-> + Xml to Pdf using Xsl (2)
-> + Using a parameter (or similar)... (2)
-> + How to avoid creating empty xm... (2)
-> + how to read txt files in xml (2)
-> + Limit records to 4 per page. P... (4)
-> + XSLT Mapping Based on JDK5 (2)
-> + XML Mappin (2)
-> + Format Datetime with xslt (3)
-> + Cell border missing (2)
-> + XSL: Key (not matches) (5)
-> + Loop through each char in stri... (2)
-> + What is the best way to sum va... (3)
-> + xslt sort help (2)
-> + getting the count (2)
-> + XSL dynamic variables (5)
-> + XSL:Key use (3)
-> + Help With Updating Attributes ... (8)
-> + GETTING COUNT AND POSITION usi... (3)
-> - Hi Everyone !! (1)
-> + Graph Traversal (Keep track of... (2)
-> + XSL IF with sum (2)
-> + Param not incrementing (2)
-> + Iterating through value tags (3)
-> + URGENT :::: Remove the name sp... (2)
-> + Pass new param values to ASP O... (2)
-> + Detect Browser Version in XSL (2)
-> + xslt result-document (2)
-> + Unique nodes based on two attr... (3)
-- Previous [181-200] [201-220] [221-240] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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>

   
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.