Schemas, xsd, xdr
Schemas, xsd, xdr Contents
Summary How to change the value of only one attribute in an XML document.
<?xml version=1.0 encoding=UTF-8?> <!DOCTYPE model [ <!ELEMENT company (company-name?, employees)> <!ELEMENT company-name (#PCDATA)> <!ELEMENT employees (employee*)> <!ELEMENT employee (first-name, last-name, salary)> <!ATTLIST employee ssn ID #REQUIRED title (developer | manager | director) developer > <!ELEMENT first-name (#PCDATA)> <!ELEMENT last-name (#PCDATA)> <!ELEMENT salary (#PCDATA)> ]> <company> <company-name>Apex Industries</company-name> <employees> <employee ssn=123-45-1001 title=developer> <first-name>Adam</first-name> <last-name>Smith</last-name> <salary>50000</salary> </employee> <employee ssn=123-45-1002 title=developer> <first-name>Brad</first-name> <last-name>Smith</last-name> <salary>50200</salary> </employee> <employee ssn=123-45-1003 title=manager> <first-name>John</first-name> <last-name>Smith</last-name> <salary>70300</salary> </employee> <employee ssn=123-45-1004 title=director> <first-name>Will</first-name> <last-name>Smith</last-name> <salary>90400</salary> </employee> </employees> </company>
<xsl:template match=/ | @* | *> <xsl:copy> <xsl:apply-templates select=@* | */> </xsl:copy> </xsl:template>
<!-- Root template. --> <xsl:template match=/> <xsl:text>&lf;</xsl:text> <xsl:text>&lf;</xsl:text> <xsl:apply-templates/> </xsl:template> <!-- Identity transform for elements. --> <xsl:template match=*> <xsl:copy> <xsl:apply-templates select=@*/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- Identity transform for attributes. --> <xsl:template match=@*> <xsl:copy-of select=./> </xsl:template>
<xsl:template match=employee/@title> <xsl:choose> <xsl:when test=.='developer'> <xsl:attribute name=title>manager</xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:copy-of select=./> </xsl:otherwise> </xsl:choose> </xsl:template>
<?xml version=1.0 ?> <!-- begin stylesheet --> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform > <!-- stylesheet output --> <xsl:output method=xml encoding=UTF-8/> <!-- Root template. --> <xsl:template match=/> <xsl:apply-templates/> </xsl:template> <!-- Identity copy of elements. --> <xsl:template match=*> <xsl:copy> <xsl:apply-templates select=@*/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- Identity copy of attributes. --> <xsl:template match=@*> <xsl:copy-of select=./> </xsl:template> <!-- Change specific attribute. --> <xsl:template match=employee/@title> <xsl:choose> <xsl:when test=.='developer'> <xsl:attribute name=title>manager</xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:copy-of select=./> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- end stylesheet --> </xsl:stylesheet>
C:\>msxsl company.xml change.xsl -o company2.xml
<?xml version=1.0 encoding=UTF-8?> <company> <company-name>Apex Industries</company-name> <employees> <employee ssn=123-45-1001 title=manager> <first-name>Adam</first-name> <last-name>Smith</last-name> <salary>50000</salary> </employee> <employee ssn=123-45-1002 title=manager> <first-name>Brian</first-name> <last-name>Smith</last-name> <salary>50200</salary> </employee> <employee ssn=123-45-1003 title=manager> <first-name>John</first-name> <last-name>Smith</last-name> <salary>90300</salary> </employee> <employee ssn=123-45-1004 title=director> <first-name>Will</first-name> <last-name>Smith</last-name> <salary>180400</salary> </employee> </employees> </company>
Partners
Dream.In.Code dotNet Slackers dotNet Spider Your HTML Source VisualBuilder.com DevGuru Planet Source Code ZVON.ORG Web Design ASPAlliance XML Pitstop Scripts
The Spot 4 SAP Bitshop Web Hosting