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
Jon GallegosSubject: The last five bytes of a variable length field
Author: Jon Gallegos
Date: 20 May 2008 03:38 PM
I have a text field where the identification number is located on the last five bytes of the field. This is number is always on the last five bytes, but the field length is dynamic.

How can I grab the last five bytes of a variable length field?

Postnext
James DurningSubject: The last five bytes of a variable length field
Author: James Durning
Date: 20 May 2008 04:00 PM
If each byte is a character, you could use something like this with string-length():

substring(.,string-length()-5,5)

Postnext
Jon GallegosSubject: The last five bytes of a variable length field
Author: Jon Gallegos
Date: 20 May 2008 04:13 PM
This didn't work for me but maybe because of my wonderfull typing abilities. Here is my code;

<xsl:value-of select="substring(b:PLMXML/b:ProductRevision/b:ApplicationRef/@version,string-length()-5,5)"/>

Postnext
Tony LavinioSubject: The last five bytes of a variable length field
Author: Tony Lavinio
Date: 20 May 2008 06:59 PM
string-length() takes as an argument the string.

So you should do something like
<xsl:variable name="x" select="...."/>
<xsl:value-of select="substring(x, string-length(x) - 4)"/>

Note that if you want the last 5 characters, you need to only
subtract 4.

Postnext
Jon GallegosSubject: The last five bytes of a variable length field
Author: Jon Gallegos
Date: 21 May 2008 08:58 AM
I am still having issues though I am sure i have a typo somewhere. Here is what I have

<xsl:variable name="x"select="b:ProductRevision/b:ApplicationRef/@version"/>
<xsl:value-of select="substring(x, string-length(x) - 4)"/>


one quick question should the substing look like this?
<xsl:value-of select="substring(x, string-length(x) - 4), 5"/>

Postnext
(Deleted User) Subject: The last five bytes of a variable length field
Author: (Deleted User)
Date: 21 May 2008 09:54 AM
Hi Jon,
there is a typo in the suggestion: variables should be referenced as $x, not just 'x'. As for the last argument of substring, if omitted it means 'until the end of the input string'.

Alberto

Posttop
Jon GallegosSubject: The last five bytes of a variable length field
Author: Jon Gallegos
Date: 21 May 2008 10:10 AM
Ahh yes the typo king strikes again

Final code looks like this

<xsl:variable name="hld1" select="@version"/>
<xsl:variable name="hld2" select="string-length(@version)-3"/>
<xsl:value-of select="substring($hld1,$hld2,4)"/>


Thanks

 
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.