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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Duplicate Ouput on Repeating E... (2)
-> + How to canculate grand total. (3)
-> + Displaying two xml files toget... (2)
-> - Replace xml attribs vals with ... (2)
-> ->Replace xml attribs vals ...
-> + check mark - font problem? (5)
-> + Xml to XML with XSLT (Remove) (10)
-> + Problem viewing xml as html wi... (4)
-> + Need to create lunk through XM... (2)
-> - Pagination with xslt (1)
-> + Transform to text using xslt (5)
-> + Rotating text using XSL FO (2)
-> + XSL -- Trim blanks from a vari... (3)
-> + dynamic matching (4)
-> + XSL:key for each condition - p... (5)
-> + XSL does not sort (5)
-> + CAN i CREATE INTERMEDIATE XML ... (2)
-> + Xml to html conversion (3)
-> + Using Xpath against Variables ... (9)
-> + XML-22004: (Fatal Error) Error... (10)
-> + Current page number (3)
-- Previous [1381-1400] [1401-1420] [1421-1440] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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>

   
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.