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, 08:58 AM
Authorized User
Points: 50, Level: 1
Points: 50, Level: 1 Points: 50, Level: 1 Points: 50, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default syntax for a processing loop

I'm having some trouble finding the correct syntax for a loop I'm trying using msxsl command line processor to parse an xml file. I have a date tag that gives me a substring that will vary in length from 8 - 10 characters depending on the day and month ( example: 3/3/2006 or 12/12/2006) I want my substring "value-of select" below to look at the total length of the substring( whether it be 8,9 or 10) and return only the last 2 characters for my date. Any suggestions about how to do this would be appreciated.

dmhollis



<xsl:value-of select="substring(.,7,2)"/>
<xsl:choose>

        <xsl:when test="substring(. ,4,3)
='Jan'">
                                                 <xsl:value-of select
="'01'"/>

Reply With Quote
  #2 (permalink)  
Old September 2nd, 2006, 12:04 PM
mhkay's Avatar
Wrox Author
Points: 17,682, Level: 57
Points: 17,682, Level: 57 Points: 17,682, Level: 57 Points: 17,682, Level: 57
Activity: 25%
Activity: 25% Activity: 25% Activity: 25%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,825
Thanks: 0
Thanked 263 Times in 258 Posts
Default

I can't relate the description of the problem to your code fragment. What exactly is your input and your desired output?

In general, if you're dealing with input that has variable length components separated by delimiter characters, you want to process it using substring-before and substring-after, not using substring, which is designed for extracting fixed-length fields at a fixed position.

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 7th, 2006, 02:29 PM
Authorized User
Points: 50, Level: 1
Points: 50, Level: 1 Points: 50, Level: 1 Points: 50, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My input date format is 3/3/2006 and my output format needs to be 060303 or for a two digit date input like 11/25/2006 it would need to be 061125. Basically for each date tag I need a loop that looks at the day,month,year and reorders it and drops each /. The loop structure I posted before worked for a date format like 01Sep06 and I was trying to figure out how to incorporate that for the new input tags with variable month sizes.

Reply With Quote
  #4 (permalink)  
Old September 7th, 2006, 02:44 PM
mhkay's Avatar
Wrox Author
Points: 17,682, Level: 57
Points: 17,682, Level: 57 Points: 17,682, Level: 57 Points: 17,682, Level: 57
Activity: 25%
Activity: 25% Activity: 25% Activity: 25%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,825
Thanks: 0
Thanked 263 Times in 258 Posts
Default

In XSLT 2.0, use regular expressions.

In 1.0, You just need to pick out the components of the date using substring-before and substring-after, e.g. the second component is substring-before(substring-after($in, '/'), '/'). Then you can use format-number to add a leading zero, and concat() to put the three parts together in the right order.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
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
Collection-based for loop syntax question. drosenbaum BOOK: Beginning Java 2, JDK 5 Edition 0 March 5th, 2007 06:19 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 2.0 Professional 2 November 29th, 2006 11:19 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy General .NET 2 January 13th, 2006 07:43 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 1.0 and 1.1 Professional 2 December 15th, 2005 03:16 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy Classic ASP Professional 0 December 13th, 2005 07:19 AM



All times are GMT -4. The time now is 03:07 AM.


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