XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Andy EshtrySubject: Replace xml attribs vals with xslt
Author: Andy Eshtry
Date: 30 Jul 2006 07:19 PM
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 steve_eshtry@hotmail.com.
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)

P.S I think I need to change this line (see xslt bellow) by replacing "." (which is used for searcning elements) with another keyword to search only attributes. Any idea?

<xsl:with-param name="outputString" select="."/>

HERE IS XSLT (INPUT PARAMS ARE $drive1target AND $drive1replacement)

<!-- xq332.xsl: converts xq331.xml into xq333.xml -->
<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">

Posttop
James DurningSubject: Replace xml attribs vals with xslt
Author: James Durning
Date: 31 Jul 2006 01:27 PM
Firstly change <xsl:template match="text()">
to <xsl:template match="text()|@*">
@* picks up the attributes.

Also, you will need to apply templates to the attribute notes.
Did you have a template to pick up element nodes?
eg.
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates match="node()"/>
</xsl:copy>
</xsl:template>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.