Subject: RE: [xsl] Unable to get text() of node From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Sat, 21 Jan 2006 21:55:51 -0000 |
One solution which no-one seems to have suggested is to strip all the whitespace text nodes using <xsl:strip-space elements="*"/> and then access child::text()[1] On advantage is that you will then get the same result from MSXML, which strips whitespace text nodes by default, as from everything else, which doesn't. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Liron [mailto:magilam@xxxxxxxxxxxxxxxx] > Sent: 21 January 2006 20:35 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] Unable to get text() of node > > Hi Andrew, > > Thank you very much for your reply. > > It works! > > As for your mixed content comment - You're absolutely right > but I'm taking > care of it. > In my project I'm actually applying xsl on html thus the use of mixed > content for children. > > Thanks again, I'm learning a lot from all the replies I get > Liron > > ----- Original Message ----- > From: "andrew welch" <andrew.j.welch@xxxxxxxxx> > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > Sent: Saturday, January 21, 2006 8:59 PM > Subject: Re: [xsl] Unable to get text() of node > > > > You can use the following stylesheet: > > > > <xsl:stylesheet version="1.0" > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > > > <xsl:template match="/"> > > <tree> > > <xsl:apply-templates select="tree/child[childname]"/> > > </tree> > > </xsl:template> > > > > <xsl:template match="child"> > > <childText> > > <xsl:apply-templates/> > > </childText> > > </xsl:template> > > > > <xsl:template match="childname"/> > > > > </xsl:stylesheet> > > > > But I would suggest that you source XML structure should be changed > > because when you have: > > > > <node> > > <child/> > > Some text > > </node> > > > > All the presentational whitespace surrounding "Some text" is part of > > the value (the first carriage return, the indentation and the second > > CR), which is not the intention. > > > > Having mixed content like that isn't really suitable for > data-centric > > XML as this problem has demonstrated - its much better to have an > > element for each value, and each element should only contain other > > elements, or text, but not both eg: > > > > <node> > > <child/> > > <child>Some text</child> > > </node> > > > > cheers > > andrew
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Unable to get text() of n, Liron | Thread | Re: [xsl] Unable to get text() of n, Kasimier Buchcik |
Re: [xsl] Unable to get text() of n, Liron | Date | Re: [xsl] Unable to get text() of n, Andrew Franz |
Month |