Subject: RE: [xsl] normalize-space(me) From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx> Date: Mon, 17 Jun 2002 14:29:41 +0100 |
>I am trying to normalize the hard returns, tabs and extra spaces in >nodes that have children. I have tried a number of different usages >of normalize-space() but nothing seems to work. What about an identity transform with normalising on the text() <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="text()"> <xsl:value-of select="normalize-space(.)"/> </xsl:template> This will give you everything on one line, is that what you want? To give it some structure you could always use output indent="yes" (which Im sure you're aware of) cheers andrew -----Original Message----- From: Mike Ferrando [mailto:mikeferrando@xxxxxxxxx] Sent: 17 June 2002 13:54 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] normalize-space(me) Dear friends, I am trying to normalize the hard returns, tabs and extra spaces in nodes that have children. I have tried a number of different usages of normalize-space() but nothing seems to work. I began to use normalize-space in an effort to dectect errors in coding legacy finding aids. Some elements would only have nested nodes and some nodes would only have text. So I used normalize-space to find these errors (text where it should not be in the xml document). I used node()[normalize-space(.)]. This would allow me to find text in a node no matter where it appeared, before or after any children in the node. But now I am not so sure that it works correctly. Initally my object was to create a template that would detect any children of the current node it was processing. In this instance the node is TITLE. If there was a child node, then it would use xsl:copy-of, but if not it would call the node with xsl:value-of. I then wanted to normalize the space within the node so that even if there was a child node any line breaks, tabs or extra spaces would be normalized into one line. Of course this code is created for testing real documents. Could anyone help me out. I thought I might use translate() but I am not sure if I really need to do that. Sincerely, Mike Ferrando Washington, DC What I have is: <TT> <T1> <TITLE>This is a normal title</TITLE> </T1> <T1> <TITLE>This is <S>not</S> a normal title</TITLE> </T1> </TT> This is what I want: <TITLE>This is a normal title</TITLE> <TITLE>This is <S>not</S> a normal title</TITLE> This is my xsl: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output version="1.0" method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="no" standalone="no" media-type="text/xml"/> <!-- Indent turned off --> <xsl:template match="/"> <xsl:text>
</xsl:text> <xsl:comment> <xsl:value-of select="concat(' Transformed with ', $replace, '.xsl ')"/> </xsl:comment> <xsl:text>
</xsl:text> <C01> <xsl:apply-templates select="//T1"/> <xsl:text>
</xsl:text> </C01> </xsl:template> <xsl:template match="T1"> <xsl:text>
</xsl:text> <T1> <xsl:apply-templates select="TITLE"/> <xsl:text>
</xsl:text> </T1> </xsl:template> <xsl:template match="TITLE"> <xsl:variable name="nest" select="child::*/node()"/> <xsl:text>
</xsl:text> <TITLE> <xsl:choose> <xsl:when test="$nest"> <xsl:copy-of select="concat('nnn', $nest, 'nnn', node()[normalize-space(.)])"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat('nnn', $nest, 'nnn', normalize-space(node()))"/> </xsl:otherwise> </xsl:choose> </TITLE> </xsl:template> </xsl:stylesheet> __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] cocoon or xalan, Steven Noels | Thread | [xsl] is it possible to construct n, Meir |
Re: [xsl] How to execute an express, CAO Tuan Dung | Date | [xsl] is it possible to construct n, Meir |
Month |