Author : Number of characters

Hi, Is it possible to know simply the number of characters in a xml file? I use Author version 10.2 on Mac OS X. Best Regards, _______________________________________ Isabelle Rogie Database Chief project Wolters Kluwer France

Hi Isabelle, We have some plans to add actions in Oxygen for counting words and characters. In the meantime you can create an XSLT stylesheet with the following content: <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match='/'> <xsl:text>The document contains </xsl:text> <xsl:call-template name='add'> <xsl:with-param name='nodes' select='//text()'/> </xsl:call-template> <xsl:text> characters. </xsl:text> </xsl:template> <xsl:template name='add'> <xsl:param name='sum' select='0'/> <xsl:param name='nodes' select='/..'/> <xsl:choose> <xsl:when test='not($nodes)'> <xsl:value-of select='$sum'/> </xsl:when> <xsl:otherwise> <xsl:call-template name='add'> <xsl:with-param name='sum' select='$sum + string-length($nodes[1])'/> <xsl:with-param name='nodes' select='$nodes[position() != 1]'/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> and apply it on the XML file. If you need to count words, there is an XSLT stylesheet available here: http://tech.groups.yahoo.com/group/dita-users/message/11854 Regards, Radu -- Radu Coravu <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 5/7/2010 5:19 PM, Rogie Isabelle wrote:
Hi,
Is it possible to know simply the number of characters in a xml file?
I use Author version 10.2 on Mac OS X.
Best Regards,
_______________________________________
**Isabelle Rogie**
Database Chief project
Wolters Kluwer France
_______________________________________________ oXygen-user mailing list oXygen-user@oxygenxml.com http://www.oxygenxml.com/mailman/listinfo/oxygen-user

Hello, Thanks for this idea! I just add the function normalize-space to suppress space on this line: <xsl:with-param name='sum' select='$sum + string-length(normalize-space($nodes[1]))'/> I wanted only the number of characters in element p. So I change the selection: <xsl:with-param name='nodes' select='//p/text()'/> But it doesn't work. The number of characters is 0 Regards, Isabelle Rogie -----Message d'origine----- De : Radu Coravu [mailto:radu_coravu@sync.ro] Envoyé : lundi 10 mai 2010 11:18 À : oxygen-user@oxygenxml.com Objet : Re: [oXygen-user] Author : Number of characters Hi Isabelle, We have some plans to add actions in Oxygen for counting words and characters. In the meantime you can create an XSLT stylesheet with the following content: <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match='/'> <xsl:text>The document contains </xsl:text> <xsl:call-template name='add'> <xsl:with-param name='nodes' select='//text()'/> </xsl:call-template> <xsl:text> characters. </xsl:template> <xsl:template name='add'> <xsl:param name='sum' select='0'/> <xsl:param name='nodes' select='/..'/> <xsl:choose> <xsl:when test='not($nodes)'> <xsl:value-of select='$sum'/> </xsl:when> <xsl:otherwise> <xsl:call-template name='add'> <xsl:with-param name='sum' select='$sum + string-length($nodes[1])'/> <xsl:with-param name='nodes' select='$nodes[position() != 1]'/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> and apply it on the XML file. If you need to count words, there is an XSLT stylesheet available here: http://tech.groups.yahoo.com/group/dita-users/message/11854 Regards, Radu -- Radu Coravu <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 5/7/2010 5:19 PM, Rogie Isabelle wrote:
Hi,
Is it possible to know simply the number of characters in a xml file?
I use Author version 10.2 on Mac OS X.
Best Regards,
_______________________________________
**Isabelle Rogie**
Database Chief project
Wolters Kluwer France
_______________________________________________ oXygen-user mailing list oXygen-user@oxygenxml.com http://www.oxygenxml.com/mailman/listinfo/oxygen-user

Dear Isabelle, You can use also the XPath evaluation (see the XPath edit box in the toolbar). To get the normalized text from the document you can use normalize-space(/*) and for the number of characters in this text use string-length(normalize-space(/*)) For understanding the problem you have with the stylesheet please post also a sample XML file together with the stylesheet that you use. Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 5/10/10 5:56 PM, Rogie Isabelle wrote:
Hello,
Thanks for this idea! I just add the function normalize-space to suppress space on this line: <xsl:with-param name='sum' select='$sum + string-length(normalize-space($nodes[1]))'/>
I wanted only the number of characters in element p. So I change the selection: <xsl:with-param name='nodes' select='//p/text()'/> But it doesn't work. The number of characters is 0
Regards,
Isabelle Rogie
-----Message d'origine----- De : Radu Coravu [mailto:radu_coravu@sync.ro] Envoyé : lundi 10 mai 2010 11:18 À : oxygen-user@oxygenxml.com Objet : Re: [oXygen-user] Author : Number of characters
Hi Isabelle,
We have some plans to add actions in Oxygen for counting words and characters. In the meantime you can create an XSLT stylesheet with the following content:
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'> <xsl:text>The document contains</xsl:text> <xsl:call-template name='add'> <xsl:with-param name='nodes' select='//text()'/> </xsl:call-template> <xsl:text> characters. </xsl:template>
<xsl:template name='add'> <xsl:param name='sum' select='0'/> <xsl:param name='nodes' select='/..'/>
<xsl:choose> <xsl:when test='not($nodes)'> <xsl:value-of select='$sum'/> </xsl:when> <xsl:otherwise> <xsl:call-template name='add'> <xsl:with-param name='sum' select='$sum + string-length($nodes[1])'/> <xsl:with-param name='nodes' select='$nodes[position() != 1]'/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
and apply it on the XML file. If you need to count words, there is an XSLT stylesheet available here: http://tech.groups.yahoo.com/group/dita-users/message/11854
Regards, Radu

An xml example : <?xml version="1.0" encoding="UTF-8"?> <NewsMLwk> <NewsItemId>WK20100201-01</NewsItemId> <OfInterestTo FormalName="WKF"/> <HeadLine/> <DateLine/> <body.content> <p>Par <aut/></p> <p>PARIS, 2010 -</p> </body.content> </NewsMLwk> With this xsl : <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:text>The document contains </xsl:text> <xsl:call-template name="add"> <xsl:with-param name="nodes" select="//p/text()"/> </xsl:call-template> <xsl:text> characters.</xsl:text> </xsl:template> <xsl:template name="add"> <xsl:param name="sum" select="0"/> <xsl:param name="nodes" select="/.."/> <xsl:choose> <xsl:when test="not($nodes)"> <xsl:value-of select="$sum"/></xsl:when> <xsl:otherwise> <xsl:call-template name="add"> <xsl:with-param name="sum" select="$sum + string-length(normalize-space($nodes[1]))"/> <xsl:with-param name="nodes" select="$nodes[position() != 1]"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Le 10/05/10 17:06, « George Cristian Bina » <george@oxygenxml.com> a écrit :
Dear Isabelle,
You can use also the XPath evaluation (see the XPath edit box in the toolbar). To get the normalized text from the document you can use
normalize-space(/*)
and for the number of characters in this text use
string-length(normalize-space(/*))
For understanding the problem you have with the stylesheet please post also a sample XML file together with the stylesheet that you use.
Best Regards, George

Hi Isabelle, You can just use the following XPath expression: sum(//p/string-length(normalize-space())) The stylesheet works ok for me, it gives as output: "The document contains 16 characters." Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 5/10/10 6:18 PM, I. Rogie wrote:
An xml example :
<?xml version="1.0" encoding="UTF-8"?> <NewsMLwk> <NewsItemId>WK20100201-01</NewsItemId> <OfInterestTo FormalName="WKF"/> <HeadLine/> <DateLine/> <body.content> <p>Par<aut/></p> <p>PARIS, 2010 -</p> </body.content> </NewsMLwk>
With this xsl :
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:text>The document contains</xsl:text> <xsl:call-template name="add">
<xsl:with-param name="nodes" select="//p/text()"/> </xsl:call-template> <xsl:text> characters.</xsl:text> </xsl:template>
<xsl:template name="add"> <xsl:param name="sum" select="0"/> <xsl:param name="nodes" select="/.."/> <xsl:choose> <xsl:when test="not($nodes)"> <xsl:value-of select="$sum"/></xsl:when> <xsl:otherwise> <xsl:call-template name="add"> <xsl:with-param name="sum" select="$sum + string-length(normalize-space($nodes[1]))"/> <xsl:with-param name="nodes" select="$nodes[position() != 1]"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Le 10/05/10 17:06, « George Cristian Bina »<george@oxygenxml.com> a écrit :
Dear Isabelle,
You can use also the XPath evaluation (see the XPath edit box in the toolbar). To get the normalized text from the document you can use
normalize-space(/*)
and for the number of characters in this text use
string-length(normalize-space(/*))
For understanding the problem you have with the stylesheet please post also a sample XML file together with the stylesheet that you use.
Best Regards, George

Hi, Thanks for your help! I found another solution; I added a predicat in the select node with specific ancestor axis. <xsl:template match="/"> <xsl:text>The document contains </xsl:text> <xsl:call-template name="add"> <xsl:with-param name="nodes" select="//text()[ancestor::p|ancestor::HeadLine]"/> </xsl:call-template> <xsl:text> characters.</xsl:text> </xsl:template> Regards, Isabelle -----Message d'origine----- De : George Cristian Bina [mailto:george@oxygenxml.com] Envoyé : mardi 11 mai 2010 07:57 À : Rogie Isabelle Cc : Radu Coravu; oxygen-user@oxygenxml.com Objet : Re: [oXygen-user] Author : Number of characters Hi Isabelle, You can just use the following XPath expression: sum(//p/string-length(normalize-space())) The stylesheet works ok for me, it gives as output: "The document contains 16 characters." Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 5/10/10 6:18 PM, I. Rogie wrote:
An xml example :
<?xml version="1.0" encoding="UTF-8"?> <NewsMLwk> <NewsItemId>WK20100201-01</NewsItemId> <OfInterestTo FormalName="WKF"/> <HeadLine/> <DateLine/> <body.content> <p>Par<aut/></p> <p>PARIS, 2010 -</p> </body.content> </NewsMLwk>
With this xsl :
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:text>The document contains</xsl:text> <xsl:call-template name="add">
<xsl:with-param name="nodes" select="//p/text()"/> </xsl:call-template> <xsl:text> characters.</xsl:text> </xsl:template>
<xsl:template name="add"> <xsl:param name="sum" select="0"/> <xsl:param name="nodes" select="/.."/> <xsl:choose> <xsl:when test="not($nodes)"> <xsl:value-of select="$sum"/></xsl:when> <xsl:otherwise> <xsl:call-template name="add"> <xsl:with-param name="sum" select="$sum + string-length(normalize-space($nodes[1]))"/> <xsl:with-param name="nodes" select="$nodes[position() != 1]"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Le 10/05/10 17:06, « George Cristian Bina »<george@oxygenxml.com> a écrit :
Dear Isabelle,
You can use also the XPath evaluation (see the XPath edit box in the toolbar). To get the normalized text from the document you can use
normalize-space(/*)
and for the number of characters in this text use
string-length(normalize-space(/*))
For understanding the problem you have with the stylesheet please post also a sample XML file together with the stylesheet that you use.
Best Regards, George
participants (4)
-
George Cristian Bina
-
I. Rogie
-
Radu Coravu
-
Rogie Isabelle