finding largest sting length in xml nodes using XSLT
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Mon Mar 28, 2005 9:34 pm
finding largest sting length in xml nodes using XSLT
Post by bharath_pepala »
hi friends,
I have the following xml file.
<?xml version='1.0' encoding='UTF-8'?>
<lifesequencechart>
<table rows="15">
<lifeline id="1">obj1</lifeline>
<lifeline id="2">obj2222222</lifeline>
<lifeline id="3">obj3332</lifeline>
<lifeline id="4">obj4444</lifeline>
</table>
</lifesequencechart>
My question is how to find out the largest string length of <lifeline> using XSLT.
Can anyone help me how to find out this string length??
thanks,
Bharath
I have the following xml file.
<?xml version='1.0' encoding='UTF-8'?>
<lifesequencechart>
<table rows="15">
<lifeline id="1">obj1</lifeline>
<lifeline id="2">obj2222222</lifeline>
<lifeline id="3">obj3332</lifeline>
<lifeline id="4">obj4444</lifeline>
</table>
</lifesequencechart>
My question is how to find out the largest string length of <lifeline> using XSLT.
Can anyone help me how to find out this string length??
thanks,
Bharath
-
- Posts: 5
- Joined: Wed Jan 05, 2005 1:07 pm
do you search something like list?...
<xsl:apply-templates select="lifeline">
<xsl:sort select="string-length()" order="descending" data-type="number" />
</xsl:apply-templates>
...or only one single number? then you have to create a new xml (as far i don't know how one can copy a part of your old one and e.g. sort another part - maybe someone can help?):
<xsl:template match="/lifesequencechart">
<xsl:element name="root">
<xsl:apply-templates select="table/lifeline">
<xsl:sort select="string-length()" order="descending" data-type="number" />
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="lifeline">
<xsl:element name="newLifeline">
<xsl:value-of select="string-length()" />
</xsl:element>
</xsl:template>
and now you use the resulting xml and the following xsl:
<xsl:template match="/root">
<xsl:value-of select="lifeline[1]" />
</xsl:template>
<xsl:apply-templates select="lifeline">
<xsl:sort select="string-length()" order="descending" data-type="number" />
</xsl:apply-templates>
...or only one single number? then you have to create a new xml (as far i don't know how one can copy a part of your old one and e.g. sort another part - maybe someone can help?):
<xsl:template match="/lifesequencechart">
<xsl:element name="root">
<xsl:apply-templates select="table/lifeline">
<xsl:sort select="string-length()" order="descending" data-type="number" />
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="lifeline">
<xsl:element name="newLifeline">
<xsl:value-of select="string-length()" />
</xsl:element>
</xsl:template>
and now you use the resulting xml and the following xsl:
<xsl:template match="/root">
<xsl:value-of select="lifeline[1]" />
</xsl:template>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Bharath,
Should print the max length.
Best Regards,
George
Code: Select all
<xsl:template match="/">
<xsl:value-of select="string-length(
lifesequencechart/table/lifeline/text() [
string-length(.) > string-length(../following-sibling::lifeline/text())
]
)"/>
</xsl:template>
Best Regards,
George
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