xsl-list
[Top] [All Lists]

Re: manipulating text and not losing elements

2005-10-13 08:17:41

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(_dot_)robinson(_at_)stanford(_dot_)edu
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>