f

#### XSLT Delimited Text Node

Is there a way in XSLT to match on numbers that are delimited by a character
or space in a text node?


 0
emailMK (37)
2/28/2005 8:38:25 PM
comp.text.xml 8781 articles. 0 followers.

1 Replies
465 Views

Similar Articles

[PageSpeed] 54


Mike King wrote:

> Is there a way in XSLT to match on numbers that are delimited by a character
> or space in a text node?

XSLT 2.0 can do that nicely with the tokenize XPath 2.0 function e.g.
with the input being

<?xml version="1.0" encoding="UTF-8"?>
<root>
<data-list>1 2 3 4 5</data-list>
</root>

and the stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="data-list">
<xsl:copy>
<xsl:for-each select="tokenize(., '\s+')">
<data><xsl:value-of select="." /></data>
</xsl:for-each>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

the result using Saxon 8.3 is

<?xml version="1.0" encoding="UTF-8"?>
<root>
<data-list>
<data>1</data>
<data>2</data>
<data>3</data>
<data>4</data>
<data>5</data>
</data-list>
</root>

If you want to use XSLT 1.0 then you need to write a recursive template
taking the string with the numbers as the argument and splitting it up
using XPath 1.0 functions like substring-before, substring-after etc.

--

Martin Honnen
http://JavaScript.FAQTs.com/

 0
mahotrash (2052)
3/1/2005 2:17:38 PM

Similar Artilces:

XSLT Select nodes without text-node children whose names starts with specifix text
Question on XSL expression Got this XML: <Body> <Page> <Line no="9" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="10" detail="true"> <onefield>onefieldstext</onefield> <fgman9>fgmanfieldstext</fgman9> <twofield>twofieldstext</twofield> </Line> <Line no="11" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="12" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="13" detail="true"> <onefield>onefieldstext</onefield> <fgman5>fgmanfieldstext</fgman5> <twofield>twofieldstext</twofield> </Line> <Line no="14" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> </Page> </Body> I would select the <Line/> nodes without text-node children whose names is starting with "fgman" - in this example it is all <Line/> _except_ <fgman9/> and <fgman5/> in <Line/> with @no of 10 and 13. I know that this works: &...

text-text
Wondering how what I input to my UTF-8 terminal gets passed along through my patched [1] trn ... Cyrillic: А Б В Г Д Е Ж З И Й К Л М Н О П а б в г д е ж з и й к л м н о п IPA: ᴀ ᴁ ᴂ ᴃ ᴄ ᴅ ᴆ ᴇ ᴈ ᴉ ᴊ ᴋ ᴌ ᴍ ᴎ ᴏ ɀ Ɂ ɂ Ƀ Ʉ Ʌ Ɇ ɇ Ɉ ɉ Ɋ ɋ Ɍ ɍ Ɏ ɏ [1] https://groups.google.com/d/msg/comp.sys.raspberry-pi/7Z37Hdrm0DM/6aqD-reXFzAJ ...

text + text
What is "text + text" supposed to do right now? It doesn't seem very useful to me. What about making "text + text" as an equivalent for "text || text"? Most strongly-typed programming languages do this. And MS SQL Server too, I think (CMIIW). -- dave ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org Am Freitag, 8. Oktober 2004 12:57 schrieb David Garamond: > What is "text + text" supposed to do right now? Nothing. > What about making "text + text" as an equivalent for "text > || text"? Most strongly-typed programming languages do this. And MS SQL > Server too, I think (CMIIW). What would this gain except for bloat? It's not like SQL is utterly compatible with any programming language; users will still have to learn all the operators anyway. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match Peter Eisentraut wrote: >>What is "text + text" supposed to do right now? > > Nothing. Then are these bugs? (7.4.5 and 8.0.0beta1 give same results). Frankly, the current behaviour is quite strange to me. ------------------ =...

XML DOM: XML/XHTML inside a text node
In my program, I get input from the user and insert it into an XHTML document. Sometimes, this input will contain XHTML, but since I'm inserting it as a text node, xml.dom.minidom escapes the angle brackets ('<' becomes '&lt;', '>' becomes '&gt;'). I want to be able to override this behavior cleanly. I know I could pipe the input through a SAX parser and create nodes to insert into the tree, but that seems kind of messy. Is there a better way? Thanks. On Thu, 2 Nov 2005 noahlt@gmail.com wrote: > In my program, I get input from the us...

xml to delimited text
Any suggestions on coverting xml to a delimited text file? I'm looking for a simple client side routine to import xml into MS Access. <Frank> wrote in message news:nuioov4bc2pe96ubkmcf9405e3kqr0j11l@4ax.com > Any suggestions on coverting xml to a delimited text file? I'm > looking for a simple client side routine to import xml into MS Access. If you are looking for suggestions... Here is one: Use XSL. ;-) If you want more specific answers ask more specific questions. Martin A fragment of the XML document would look like the following: <recording> <video> <name>Gone With The Wind</name> <star>Clark Gable</star> <year_released>1950</year_released> </video> </recording> The resulting delimited text file would look like this: Gone With The Wind, Clark Gable, 1950, I assume that I would need an application to strip the XML tag names from the original document and not a process using XSLT. Is this correct? The commas are immaterial. All I want to do is to be able to feed the contents of an XML document into an Access database. What do I use to do this. On Wed, 15 Oct 2003 12:00:06 +0200, "Martin Boehm" <ng.tomalak@arcor.de> wrote: ><Frank> wrote in message news:nuioov4bc2pe96ubkmcf9405e3kqr0j11l@4ax.com > >> Any suggestions on coverting xml to a delimited text file? I'm >> looking for a simple client side routine to import xml...

xslt help needed with element nodes embedded in text node
I'm but an amateur with xsl stylesheets. I need some help to the output of text nodes with embedded element nodes like the following: <uf><ns>This</ns> example</uf> <uf>Another <ns>This</ns> example</uf> <uf>Another <ns>This</ns></uf> I need to output the ns strings in italics. <xsl:apply-templates select="./uf" /> <xsl:template match="ns"> <i><xsl:value-of select="." /></i> </xsl:template> As long as the xml file is exported in lines as above the output is ok: "This example". (In this email I don't indicate the italicised part string.) But lately the document server hosting the application that contains xml files of the sort above changed the export of xml files. Now there are line breaks at each new element boundary: <uf> <ns>This</> example </uf> With my xsl code I get an additional space at the beginning and the end of the phrase: " This example ". I tried to get rid of them with <xsl:template match="text()"> <xsl:value-of select="normalize-space()" /> </xsl:template> But this results in "Thisexample". What is to be done? (There is no option to substitute the mandatory spaces with &#160;). Volker I tried <xsl:strip-space elements="uf" />. It doesn't help either. Volker Volker Le...

file command: "XML document text" vs "XML document text"
I've just used the file command on four files of RDF-XML with the following output: augtfidf.rdf: XML document text kyoto.rdf: XML document text stuff.rdf: XML document text tfidf.rdf: XML document text What does it mean that one of them has an extra space between "XML" and "document"? -- The kid's a hot prospect. He's got a good head for merchandising, an agent who can take you downtown and one of the best urine samples I've seen in a long time. [Dead Kennedys t-shirt] On 16.10.2012 16:06, Adam Funk wrote: > I've just used the file command on four files of RDF-XML with the > following output: > > augtfidf.rdf: XML document text > kyoto.rdf: XML document text > stuff.rdf: XML document text > tfidf.rdf: XML document text > > What does it mean that one of them has an extra space between "XML" > and "document"? Hard to tell without further information. What does file *.rdf | od -c show you? Janis Janis Papanagnou wrote: > On 16.10.2012 16:06, Adam Funk wrote: >> I've just used the file command on four files of RDF-XML with the >> following output: >> >> augtfidf.rdf: XML document text >> kyoto.rdf: XML document text >> stuff.rdf: XML document text >> tfidf.rdf: XML document text >> >> What does it mean that one ...

Surrounding text with text
I was wondering if it was possible to surround a text body with text like so: +--------------+ |ABCDEFGHIJKLM | |H N| |A Main Body O| |L Text goes P| |B here Q| |-=+_ZYXWVUTSR | | | | | | | | | +--------------+ This seems far-fetched, but just curious. I suppose that I could just move stuff around by hand in the GIMP later on, but there's probably a {better,more {extensible,clean}} way of doing it from (La)TeX. -FreeSmith ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<bffbhe$per$1@news.eusc.inter.net>... > Peter Flynn had an example like that, which he either posted here or > posted a link here. It was something to do with a certificate -- try > searching for his name and that word in google. > > It wouldn't be hard to do with metapost. I have a macro called `pathalong' > which puts text along an arbitrary path. Well, it's been a while, but I finally finished it. It's a little job I was doing for an upcoming wedding. At any rate, I used pstricks to make the text go along a path, along with a couple of hacks for sizing (from graphicx) and kerning along the line (from soul). Here's the code (don't laugh): CAUTION:THIS CODE MAY MAKE YOU WRETCH ---SNIP--- \documentclass{article} \usepackage{graphicx} \usepackage{pstricks,pst-text,nopageno} \usepackage[width=8.5in]{geometry} \usepackage{soul} \begin{document} \thispagestyle{empty} \set...

Text from required text box to read-only text box
Hello, I am fairly new to JavaScript and its use in Acrobat Professional. My situation is this: I have a form with a text box field which is required for the user to enter his/her name. I would like the required text box to display the name in all caps. I also need the user's name to appear in a read-only text box later in the form, which I would like to have the first letter of the user's first, middle initial, and last names to be capitalized. I would also like to have all required fields on the form highlighted in yellow, but the highlighting not printed. Lastly, I would like the...

extracting text from an XML node
Hi, suppose i get the simple xml sample: <foo> 1 <bar>2</bar> 3 </foo> Now suppose i want to extract all the text of only the 'foo' node, ie expected result is '1 3'. I tried both <xsl:template match="foo"> <xsl:value-of select="text()" /> </xsl:template> and <xsl:template match="foo"> <xsl:value-of select="." /> </xsl:template> but the former lead to '1' and the latter to '1 2 3' (using xsltproc & firefox). What did i missed ? thanks, -Nicolas nicolas.edel@gmail.com wrote: > Now suppose i want to extract all the text of only the 'foo' node That isn't a built-in concept; you have to recast it as "all the text nodes which are immediate children of the 'foo' node". (The built-in text value of an element, as you discovered, is the value of all text contained in it, directly or indirectly). Note too that the whitespace (line breaks and indentation) will be part of the the text nodes unless you explicitly strip that away. <xsl:value-of select="text()" /> didn't work because value-of returns the contents of only the first matching node. This is one case where xsl:for-each is appropriate, to explicitly iterate through the text children. -- Joe Kesselman / Beware the fury of a patient man. -- John Dryden On Nov 30, 12:34 am, Joseph Kesselman <kesh...

text 2 text

XSLT Extract Text from Nodes

text node has text but won't render
This renders in Firefox perfectly well but the text in the red box remains invisible. The program is a subset of a larger and doesn't do much. but even after cutting out all the unneccessary stuf, I still can't get it to work!! Cheers, Greg =================== <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" > <xhtml:head> <xhtml:title> Intermingled XHTML and SVG </xhtml:title> <xhtml:script type="text/javascript" language="JavaScript"><![CDATA[ function gogo(evt){ var targetObj = evt.target; //The object that received the event var targetDoc = targetObj.ownerDocument; //Owner document var wg = document.getElementById("SVGroot"); var lg = document.getElementById("labelz"); //label labelBox= targetDoc.createElementNS("http://www.w3.org/2000/svg", "svg:rect"); labelBox.setAttributeNS(null, "id", "label1"); labelBox.setAttributeNS(null, "fill", "red"); labelBox.setAttributeNS(null, "fill-opacity", 1); labelBox.setAttributeNS(null, "x", 700); labelBox.setAttributeNS(null, "y", 400); labelBox.setAttributeNS(null, "width", 200); labelBox.setAttributeNS(null, "height", 20); labelBox.setAttributeNS(null, "visibility", "visible"); lg.appendC...

Pages
I have a titel-textfield over a pic (headline) , text is black, background for text transparent. A second textfield should overlapp the first textline..... When i arrange the second field with the same settings like the first, the first text disappear... How can i do, that the second text overpapps the first, all over the pic. Any help appreciated! Thanks for replies! I am german and hope that the engish speaking people understand my problem! Soory! Gerd In article <611db9e2-b085-4fe5-907a-ca714b0c32dd@m74g2000hsh.googlegroups.com>, hurlebaus <gerd.schenk@freenet.de> wrote:...

Getting kind of abstract text snippets from text nodes
Hi everybody, I am about implementing a little search engine that searches a phrase over xml text nodes. I got that all working fine but what I want as the results is not the complete text of the textnode, I would like to make an abstract like result list (such output that you get with google searches. For eg .... I am the <b>substring</b> from a complete text node ... where "substring" is the search term. The problem is simple (I think): I want to extract all the text parts of the complete text node, where search searchterm is highlighted, surrounded by the text like 30 characters. I found an intersting post "cut down text" which is almost that what I am looking for, but there the text is just trimmed by x characters. Is anybody here, that has an "elegant" way to solve that or some hints that get me to the solution? I am not able to use regex (would be nice though) My parser is Sablotron so I am restricted to the functions that I get. (1.0). Any help is greatly appreciated. regards, Andreas W Wylach Think about dividing the text into three parts: before your target, the target itself, and after the target. Process each appropriately. If you want to report multiple instances within the same block of text, look at the standard examples of recursive text processing. -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry "Andreas W. Wylach" <aw@ioc...

XSLT: concatenating selected text nodes
in XSLT, if I want to concatenate _all_ the child text nodes, I can just do <xsl:value-of select="."> however, if I want to select and concatente only _some_ of the text nodes. for instance <xsl:value-of select=".//foo/text()"> this doesn't work as it just takes the first element in the node set. Is there any way of achieving this without using <xsl:for-each> to explicitly loop round them all? TIA Andy use copy-of not value-of David "David Carlisle" <davidc@nag.co.uk> wrote in message news:yg4r7ktpnzq.fsf@penguin.nag.co.uk... > > use copy-of not value-of > worked a treat - thanks david. > > David ...

Parsing text with link from xml with XSLT

XML Schema for Node with attribute and text
I've tried to find how to write a schema for this type of node everywhere. <Param name="FirstParam">ABCD</Param> How do i arrange a complex type that contains an attribute and a text. This : <xs:complexType name="Param"> <xs:attribute name="name" /> </xs:complexType> Result as : <invalid char="13" code="cvc-complex-type.1.2" line="3086" resource="file:///C:/WINNT/Profiles/svaillan/Desktop/XML Schema/test.xml">element Param must be empty but is not</invalid> This : <xs:complexType name="Param"> <xs:all> <xs:element name="text" type="xs:string" /> </xs:all> <xs:attribute name="name" /> </xs:complexType> Result as : <invalid char="13" code="cvc-complex-type.1.2.3" line="3086" resource="file:///C:/WINNT/Profiles/svaillan/Desktop/XML Schema/test.xml">text not allowed: |ABCD|</invalid> I just dont know where to add the unnamed <xs:element ... > tag. Anyone can help me figure this out? Thx In article <de3c2ad2.0311281339.e74b69b@posting.google.com>, Simon Vaillancourt <svaillancourt@mediagrif.com> wrote: % I've tried to find how to write a schema for this type of node % everywhere. % % <Param name="FirstParam">ABCD</Param> % % How do...

XSLT TRANSFORMATION FROM XML TO plain Text
I have an XML FILE that is to be converted to Plain Text using an XSL file. Since I just want plain text, I do not want to set any root element during transformation.And if I do not any root element during transformation, it return s "java.lang.IllegalStateException: Root element not set" exception. If I add any element for the enclosed root, it works. Note: I am using XMLOutputter object of JDOM API, packages javax.xml.transform and javax.xml.transform.stream.* Example XML file: <root><nextpart>test</nextpart></root> *******************XSL FILE that returns exception***************************** <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" indent="yes"/> <xsl:template match="root"> <xsl:text>Hello This is the content.</xsl:text> <xsl:apply-templates select="nextpart"/> </xsl:template> ........... </xsl:stylesheet> ************************xsl file**************************** ***********************XSL FILE modified***************************** <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" indent="yes"/> <xsl:template match="root"> <document> <xs...

XSLT: getting text of a node into an attribute
I have a document, lets say: <Doc> <Ele1 Att1='hello'> <Ele2 Att2='goodbye'/> </Ele1> </Doc> In XSLT I need to generate an attribute value which contains part of this document as a text string, ie: <MyOutput XML="&lt;Ele1 Att1='hello'> &lt;Ele2 Att2='goodbye'/> &lt;/Ele1>"/> I can output it easily enough at child elements (copy-of), or as a CDATA string in the element content, but I cannot find any way to get it into an attribute. What should I be doing? use <xsl:attribute name="XML"> <xsl:copy-of ...> (or whatever) </xsl:attribute> anything you put inside here will be put into the XML attribute of the node you're creating "Kevin" <kevinburges@formedix.com> wrote in message news:1bf2fce.0307310534.516abff@posting.google.com... > I have a document, lets say: > > <Doc> > <Ele1 Att1='hello'> > <Ele2 Att2='goodbye'/> > </Ele1> > </Doc> > > In XSLT I need to generate an attribute value which contains part of > this document as a text string, ie: > > <MyOutput XML="&lt;Ele1 Att1='hello'> > &lt;Ele2 Att2='goodbye'/> > &lt;/Ele1>"/> > > > I can output it easily enough at child elements (copy-of), or as a > CDATA string i...

editor for editing xml text nodes
We have xml documents which contain text imbedded as text content in some xml structures. These documents need to be translated by human translators from English into, for example, Chinese. We would like the translator to use an editor which shows him only the text content of the xml document, or gives him only editing access to the text content. The translator should be unable to touch or modify the xml tags, so that it is guaranteed that the xml-tags are unchanged when the translator returns the translated document. The translator simply replaces all English text accessible to him into Chinese text. Does anyone know an xml editing tool which has this feature, of allowing only modification to the text node content? Alois Zreindl wrote: > We have xml documents which contain text imbedded as text content in > some xml structures. > > These documents need to be translated by human translators from English > into, for example, Chinese. > > We would like the translator to use an editor which shows him only the > text content of the xml document, or gives him only editing access to > the text content. I am working on exactly this right now. It leaves the elements in element content inviolable, but allows element markup in mixed content (the only thing a translator should be touching). Please contact me by email to discuss this further. > The translator should be unable to touch or modify the xml tags, so that > it is guara...

Why treat text nodes as nodes?
One of the things I find most unnatural about most XML APIs is that they try to abstract both elements and text into some kind of "node" object when they have virtually nothing in common. The reason these APIs do it is to make it possible for both text and elements to be children of elements. But there is another way. The XPath/XQuery data model does not allow two consecutive text nodes. As far as I can tell, most XML processing software automatically merges consecutive text nodes. This means that the number of text segments directly under an element is bound by the number of sub-elements plus 1 (PIs and comments may be treated as "pseudo-elements" for this purpose). As a result, it is always possible to associate each text segment with the element immediately preceding it within the parent and associate the first text element with the parent itself. No more text nodes. The only API I know that uses this trick is the ElementTree API for Python by Fredrik Lundh (http://effbot.org/zone/element-index.htm). Each Element object has a text and tail property for the text immediately inside the element and text following it within its parent element. Elements always have a tag, attributes and and zero or more children - which are always other elements. No mixed types. The text and tail attributes are always strings. This model should be very convenient for statically-typed languages like Java or C++. I find it ironic that this idea is probably used only in Pyt...

converting a document node and children into xml text
is there a way in javascript to convert a DOM node (and it's children) into an XML text. i'd like to save the text file somewhere and then later parse it to re-create the tree. thx. jman, google grouper, wrote: > is there a way in javascript to convert a DOM node (and it's children) > into an XML text. Yes. Traverse the DOM node subtree and output XML accordingly. > i'd like to save the text file somewhere and then later parse it > to re-create the tree. Why? jman wrote: > is there a way in javascript to convert a DOM node (and it's children) > ...

Reading Text File, Text Scrolling and erase line from a text file
Hi , How can I Reading Text File, then Text Scrolling by means of keys "page UP" "page Down" and erase a specific line from a text file , when press "F2" key? Best Regards, Lidia from Poland -- ========================================= Pozdrawiam Lidiaa Lidiaa schrieb: > Hi , > > How can I Reading Text File, then Text Scrolling by means of > keys "page UP" "page Down" and erase a specific line from a text > file , when press "F2" key? > > ...

Web resources about - XSLT Delimited Text Node - comp.text.xml

Resources last updated: 3/13/2016 11:57:37 PM