XSLT help
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 3
- Joined: Wed Jul 11, 2007 3:42 pm
XSLT help
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?
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?
-
- Posts: 89
- Joined: Mon Mar 06, 2006 10:13 pm
<?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.
<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.
-
- Posts: 3
- Joined: Wed Jul 11, 2007 3:42 pm
Dateformat
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.
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.
-
- 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:
Regards,
Sorin
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
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service