XSLT help

Here should go questions about transforming XML with XSLT and FOP.
member
Posts: 3
Joined: Wed Jul 11, 2007 3:42 pm

XSLT help

Post by member »

Hi,

Can anyone please help me?

I have the xml file:

<Issue>
<IssueHistory_CreationDate>2004-01-01</IssueHistory_CreationDate>
<Status>
<Name>Find</Name>
<Amount>28</Amount>
<Name>resolved</Name>
<Amount>0</Amount>
<Name>Finished</Name>
<Amount>0</Amount>
</Status>
<IssueHistory_CreationDate>2004-01-02</IssueHistory_CreationDate>
<Status>
<Name>Find</Name>
<Amount>6</Amount>
<Name>Resolved</Name>
<Amount>6</Amount>
<Name>Finished</Name>
<Amount>4</Amount>
</Status>

But I want to sort the Fined, Resolved and Finished amount
with xslt.

I want that the xslt file generate my xml file to this:

<string>Fined</string>
<Number>28</Number>
<Number>6</Number>

<string>solved</string>
<Number>0</Number>
<Number>6</Number>

<string>Finished</string>
<Number>0</Number>
<Number>4</Number>

Does anyone know how I can do this?
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:key name="Names" match="Name" use="."/>
<xsl:template match="/Issue">
<root>
<xsl:for-each select="Status/Name[count(.|key('Names', .)[1]) = 1]">
<string>
<xsl:value-of select="."/>
</string>
<xsl:for-each select="key('Names', .)/following-sibling::Amount[1]">
<xsl:sort select="."/>
<Number>
<xsl:value-of select="."/>
</Number>
</xsl:for-each>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>

Right now you have Resolved spelt with both an uppercase and lowercase r, and then as 'solved' later, I'm assuming spelling would be consistent.
member
Posts: 3
Joined: Wed Jul 11, 2007 3:42 pm

Dateformat

Post by member »

Hi,

Thanks, But I have another question.

Do you also know how I translate 12-01-2004T12:00:00 to only 12-01-2004 without the time in xslt?

<Issue> <IssueHistory_CreationDate>2004-01-01T12:00:00</IssueHistory_CreationDate>
<Status>
<Name>test</Name>
</Status> <IssueHistory_CreationDate>2004-01-02T12:00:00</IssueHistory_CreationDate>
<Status>
<Name>test</Name>
</Status>
</Issue>

thanks.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

Use the conversion functions of XSLT 2.0. For example to convert the dateTime 2004-01-01T12:00:00 to the date 2004-01-01 use:

Code: Select all


<xsl:template match="IssueHistory_CreationDate">
<xsl:value-of select="xs:date(xs:dateTime(.))"/>
</xsl:template>

Regards,
Sorin
member
Posts: 3
Joined: Wed Jul 11, 2007 3:42 pm

Post by member »

I work in xslt version 1.0.
I want a function that works in version 1.0
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

12-01-2004T12:00:00 to only 12-01-2004
<xsl:value-of select="substring-before(., 'T')"/>
Post Reply