Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select the first 10 characters? 1

Status
Not open for further replies.

Zargo

Programmer
Mar 21, 2005
109
Hi,

I have an xml file and i want to select the first 10 characters in my XSL file from an element in the xml file is this possible?

I'm using a XML parser in Visual Basic 6.

How to do this. My XML file is look like:

<Invoice>
<Header>
<DocumentdateTime>2005-11-15T00:00:00</DocumentdateTime>
</Header>
</Invoice>

I have tried the following in my XSL file:
<xsl:value-of select="[substring,//Invoice/Header/DocumentDateTime,10]"/>

Without succes...Does anybody know how to select this?

Thanks in advance...
 
How about do it this way?
[tt]<xsl:variable name="x" select="//Invoice/Header/DocumentDateTime" />
<xsl:value-of select="substring($x,1,10)" />
[/tt]
 
Tsuji,

Wow thanksss!!! You are a genius....

By the way do you know how we can format this date into
YYYY-DD-MM ?

I'm getting now 2005-11-15, but i want 2005-15-11?

Thanks a lot!!
 
I have found it:

<xsl:value-of select="concat(substring($x,9,2),'-',substring($x,6,2),'-',substring($x,1,4))"/>

A star for my self -:)
 
A data format of yyyy-dd-mm is much less common than yyyy-mm-dd. Is it an iso standard?

In any case, a dumb alternative in slighly more general form is this.
[tt]
<xsl:variable name="z" select="substring-before($x,'T')" />
<xsl:variable name="yyyy" select="substring-before($z,'-')" />
<xsl:variable name="tmp" select="substring-after($z,'-')" />
<xsl:variable name="mm" select="substring-before($tmp,'-')" />
<xsl:variable name="dd" select="substring-after($tmp,'-')" />
<xsl:value-of select="concat($yyyy,'-',$dd,'-',$mm)" />
[/tt]
It would accommodate single digit of month or day or two digit year, just in case. It also avoids split type recursive use of template with trade off for a simpler logic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top