Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


multy string replace

From: "alexseys@-----.---" <--------@-----.--->
To: NULL
Date: 1/17/2008 10:06:00 PM
I have xml and xsl files provide below
My goal isto replace some strings in the xml whle conerting to html
I can replace one string at a time with the following anyone can help
me to replace more than that?
i.e. ** to be replaced with </BR>
and word "comment" to be replaced with a  "-"

Any help appeciated
Thank you


<?xml version="1.0"?>
<!DOCTYPE computer[<!ELEMENT computer	(hostname,idLocation*, datetime,
component*)><!ELEMENT component	(type,name,attr*)><!ELEMENT hostname
(#PCDATA)><!ELEMENT datetime	(#PCDATA)><!ELEMENT type		(#PCDATA)><!
ELEMENT name		(#PCDATA)><!ELEMENT idLocation (#PCDATA)><!ELEMENT attr
(name,value)><!ELEMENT value		(#PCDATA)>]>
<computer>
      <hostname>WHATEVER</hostname>
      <idLocation>$$$$$</idLocation>
      <datetime>1/15/2000 4:10:53 PM</datetime>
<component>
            <type>Network Files</type>
            <name>networks</name>
            <attr>
                  <name>File Content</name>
                  <value>**# &lt;network name&gt;  &lt;network
number&gt;     [aliases...]  [#&lt;comment&gt;]
**
</value>
            </attr>
      </component>

and this xsl file to format and  replace strings

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="xs fn">
  <xsl:key name='type' match='type' use='.'/>
  <xsl:output method="html" indent="yes" />
  <!-- reusable replace-string function -->
  <xsl:template name="replace-string" >
    <xsl:param name="text"/>
    <xsl:param name="from"/>
    <xsl:param name="to"/>

    <xsl:choose>
      <xsl:when test="contains($text, $from)">
        <xsl:variable name="before" select="substring-before($text,
$from)"/>
        <xsl:variable name="after" select="substring-after($text,
$from)"/>
        <xsl:variable name="prefix" select="concat($before, $to)" />
        <xsl:value-of select="$before" disable-output-escaping="yes"/>
        <xsl:value-of select="$to" disable-output-escaping="yes"/>
        <xsl:call-template name="replace-string">
          <xsl:with-param name="text" select="$after"/>
          <xsl:with-param name="from" select="$from"/>
          <xsl:with-param name="to" select="$to"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="$text"  disable-output-escaping="yes"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="/">
    <html>
      <head>
        <style type="text/css">

        </style>
          <Title>
          <xsl:value-of select="computer/hostname"/>
        </Title>
        <h1>
          <xsl:value-of select="computer/hostname"/>
        </h1>
        <Title>
          <xsl:value-of select="computer/hostname"/>
        </Title>
      </head>
      <body>
        <xsl:for-each select="//type[generate-id()=generate-
id(key('type',.)[1])]">
          <xsl:sort select="."/>
          <li>
            <a class="link">
              <xsl:attribute name="href">
                #<xsl:value-of select="."/>
              </xsl:attribute>
              <xsl:value-of select="."/>
            </a>
          </li>
        </xsl:for-each>

        <table>
          <tbody>
            <xsl:for-each select="computer/component">
              <tr>
                <th>
                  <a>
                    <xsl:attribute name="name">
                      <xsl:apply-templates select="type"/>
                    </xsl:attribute>
                    <xsl:apply-templates select="type"/>
                  </a>
                </th>
                <td>
                  <xsl:apply-templates select="name"/>
                </td>
              </tr>
              <xsl:for-each select="attr">
                <tr>
                  <td>
                    <xsl:apply-templates select="name"/>
                  </td>
                  <td>
                    <xsl:variable name="yourstring" select="value"/>
                    <xsl:call-template name="replace-string">
                      <xsl:with-param name="text" select="$yourstring"/
>
                      <xsl:with-param name="from" select="'**'"/>
                      <xsl:with-param name="to" select="'&lt;BR&gt;'"/
>
                    </xsl:call-template>
                  </td>
                </tr>
                <tr></tr>
                <tr></tr>
              </xsl:for-each>
            </xsl:for-each>
          </tbody>
        </table>
      </body>
    </html>


  </xsl:template>
</xsl:stylesheet>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent