[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: String to XML inside an XSLT
Saxon 7.1 has a new extension function saxon:parse() which allows you to turn this into a proper tree, if you know which text nodes need to be parsed. (You can do it with d-o-e, but only by serializing the tree and then re-parsing it.) <xsl:variable name="proper-tree"> <xsl:apply-templates mode="tidy-up"/> </xsl:variable> <xsl:template match="*" mode="tidy-up"> (identity template) </xsl:template> <xsl:template match="node/text()" mode="tidy-up"> <xsl:copy-of select="saxon:parse(normalize-space(.))"/> </xsl:template> Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Josh Twist > Sent: 01 May 2002 16:34 > To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' > Subject: String to XML inside an XSLT > > > This is a bit of a funny one... > I have, for example, the following XML (muchos simplified) > > <nodes> > <node> > <childnode>value</childnode> > </node> > </nodes> > > This is a little unfortunate but unavoidable as the data is a > string and the > xml object builder can't tell the difference between a normal > string and one > that should be real XML. Only the XSLT knows this (long story). > > What I need to do is parse this in XSLT as normal and access > the XML and > it's values, children, attributes etc stored in the string. > For example the > Xpath might read "/nodes/node/childnode" I've tried putting > it in variables > with and without output-escaping disabled and so on without success: > > XSLT > > <xsl:variable name="myStringXML"> > <xsl:value-of select="/nodes/node"/> > </xsl:variable> > > <xsl:for-each select="$myStringXML/childnode"> <!-- Errors here - says > $myStringXML does not evaluate to a node set --> > <xsl:value-of select="."/> > </xsl:for-each> > > Anybody know of a way to do this? Even thought the <xsl:value-of > select="/nodes/node"/> returns the value without the <s > etc it's still a > string. What I need is somekind of xml() function that turns > a string into a > real nodeset. > > We're using MSXML3. Any help would be greatly appreciated. > > Josh > > The information in this e-mail and any attachment(s) is > confidential and may be legally privileged. This e-mail is > intended solely for the addressee. If you are not the > addressee, dissemination, copying or other use of this e-mail > or any of its content is strictly prohibited and may be > unlawful. If you are not the intended recipient please inform > the sender immediately and destroy the e-mail and any copies. > E-mails and unencrypted attachments are scanned for all known > viruses. Always scan e-mail attachments for viruses before > opening them. All liability for viruses is excluded to the > fullest extent permitted by law. Any views expressed in this > message are those of the individual sender. > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|