Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: attribute manipulation in XSLT transformation attribute manipulation in XSLT transformationTo: NULL Date: 2/3/2006 5:08:00 AM Given school #1: contains attributes of name and district
<?xml version="1.0" encoding="utf-8"?>
<School name="Joy" district="Albany">
<Class>A</Class>
<Teacher>Dave</Teacher>
</School>
school #2: missing district attribute; but has additional attribute of
principle
<?xml version="1.0" encoding="utf-8"?>
<School name="Happy" principle="Joe">
<Class>B</Class>
<Teacher>Mary</Teacher>
</School>
I want to have an identity copy without "Class" element. I think
following would work:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Identity transformation -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Omit Class -->
<xsl:template match="Class"/>
</xsl:stylesheet>
Also, I want to ensure every school must have name and district
attribute; a school can have additional attribute as original as well.
And the district attribute is forced to have same value of "NY".
That is, running the school #1, I would expect following:
<?xml version="1.0" encoding="utf-8"?>
<School name="Joy" district="NY">
<Teacher>Dave</Teacher>
</School>
And running the school #2, I would expect following:
<?xml version="1.0" encoding="utf-8"?>
<School name="Happy" district="NY" principle="Joe">
<Teacher>Mary</Teacher>
</School>
Now, the question is how can I enhance the stylesheet above to do the
attribute manipulation task?
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
