[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: manipulating text and not losing elements

Subject: Re: manipulating text and not losing elements
From: "James A. Robinson" <jim.robinson@xxxxxxxxxxxx>
Date: Thu, 13 Oct 2005 08:17:41 -0700
xsl losing elements
> But what happens in the scenario where I want to remove the numbers
> right after the indent1 and paragraph tags, as far as I can see the
> only way to accomplish this is with substring, but using a substring
> requires outputting using <xsl:value-of> which negates all following
> children.  Ultimately I would like the line tagged as <indent1> to
> read the following:

What you need to remember is that text is a node type, like any other.
So you can match on text(), and furthermore you can qualify the match
to strings with numbers in front of them, etc.  The example below
shows a crude example of matching on text() and removing the first few
chars.  There are other ways of modifying the string, but I'm not sure
what your text model is, and this reflects your original solution.  :)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  
  <xsl:template match="/">
      <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="indent1">
    <p class="indent1">
      <xsl:apply-templates/>
    </p>
  </xsl:template>
  
  <xsl:template match="italic">
    <em>
      <xsl:apply-templates/>
    </em>
  </xsl:template>
  
  <xsl:template match="bold">
   <strong>
     <xsl:apply-templates/>
   </strong>
  </xsl:template>
  
  <xsl:template match="text()[matches(., '\d+ .+')]">
    <xsl:value-of select="substring(., 6)"></xsl:value-of>
  </xsl:template>
  
</xsl:stylesheet>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       jim.robinson@xxxxxxxxxxxx
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.