Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 30th, 2006, 05:58 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replace xml attribs vals with xslt

Hello Dear Friends.
I need your help today cause I need to deliver my result tomorrow. Pls send your response to my email also at [email protected].
I need to replace the value of some attributes in my xml with new values passed as parameters using xslt and vbscript mentioned bellow. It works fine for elements values not for attributes values. If you find another working xslt version, it is fine too.
Please help.
Kind Regards
Andy (Steve)
HERE IS XSLT (INPUT PARAMS ARE $drive1target AND $drive1replacement)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="drive1target"/>
<xsl:param name="drive1replacement"/>
<xsl:template name="globalReplace">
  <xsl:param name="outputString"/>
  <xsl:param name="target1"/>
  <xsl:param name="replacement1"/>
  <xsl:choose>
    <xsl:when test="contains($outputString,$target1)">
      <xsl:value-of select=
        "concat(substring-before($outputString,$target1),
               $replacement1)"/>
      <xsl:call-template name="globalReplace">
        <xsl:with-param name="outputString"
             select="substring-after($outputString,$target1)"/>
        <xsl:with-param name="target1" select="$target1"/>
        <xsl:with-param name="replacement1" select="$replacement1"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$outputString"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
<xsl:template match="text()">
  <xsl:call-template name="globalReplace">
  <xsl:with-param name="outputString" select="."/>
  <xsl:with-param name="target1" select="$drive1target"/>
  <xsl:with-param name="replacement1" select="$drive1replacement"/>
  </xsl:call-template>
</xsl:template>
HERE IS THE VBSCRIPT
Set objXML = CreateObject("MSXML2.DOMDocument.3.0")
Set objXSL = CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
objXML.validateOnParse = True
objXSL.validateOnParse = True
objXML.async = False
objXSL.async = False
objXML.load "G_MapLayOrig.xml"
objXSL.load "XSLTMain.xsl"
Set template = CreateObject("MSXML2.XSLTemplate.3.0")
template.stylesheet = objXSL
Set processor = template.createProcessor()
processor.input = objXML
processor.addParameter "drive1target","S:\"
processor.addParameter "drive1replacement","DRIVEPATH1"
processor.transform()
objXML.loadxml processor.output
processor.input = objXML
processor.addParameter "drive1target","H:"
processor.addParameter "drive1replacement","DRIVEPATH2"
processor.transform()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Objfile= objFSO.CreateTextFile("G_MapLay.xml", True)
objfile.Write processor.output
objfile.Close
HERE IS THE XML
<Settings>
<viewer_type path="S:\App.exe"><file_extension>txt</file_extension>
<file_extension>log</file_extension>
</viewer_type>
<viewer_type path="H:\Program Files\ Office\Office\winword.exe"><file_extension>doc</file_extension><file_extension>rtf</file_extension></viewer_type><viewer_type path="C:\Program Files\Windows NT\Accessories\ImageVue\kodakprv.exe">
 
Old July 30th, 2006, 06:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>I need your help today cause I need to deliver my result tomorrow.

Sorry, but I never respond to requests if they are urgent. I try to help people learn the language, I don't try to help you meet your project deadlines.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 30th, 2006, 06:48 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I understand your point Michael pretty well and I believe I need to learn the languauge because it is very useful and instresting. I am a .net programmer and xslt is not my specialty and know I faced this problem. I am trying to learn and solve the problem by myself (reading part 5.4 of http://www.w3.org/TR/xslt) know.

Anyway, if you or other friends can help me, it is much appreciated.
I promise the help does not stops me to learn that powerful useful language. ;)
Best Regards
Andy Eshtry
Toronto, Canada





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use replace function() xslt 2.0 dev.user06 XSLT 11 June 21st, 2012 04:00 AM
XSLT replace for character entities atulshin XSLT 1 November 1st, 2008 05:19 AM
xslt replace function rajesh_css XSLT 7 October 30th, 2008 08:39 PM
Cannot Update the vals in a Dynamic DetailsView Itech ASP.NET 2.0 Professional 6 April 2nd, 2008 01:59 AM
Text Replace with XSLT pendyalap XSLT 13 October 1st, 2006 05:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.