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 1st, 2006, 08:58 AM
Authorized User
 
Join Date: Feb 2005
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'"/>

 
Old September 2nd, 2006, 12:04 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old September 7th, 2006, 02:29 PM
Authorized User
 
Join Date: Feb 2005
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.

 
Old September 7th, 2006, 02:44 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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





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 07:19 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 2.0 Professional 2 November 29th, 2006 12:19 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy General .NET 2 January 13th, 2006 08:43 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 1.0 and 1.1 Professional 2 December 15th, 2005 04:16 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy Classic ASP Professional 0 December 13th, 2005 08:19 AM





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