xslt copy-of without children

hi i have a sitemap xml document that looks something like this

<pagenode title="home" url="~/" fornavbar="true">
 <pagenode title="admin" url="~/admin" fornavbar="false">
  <pagenode title="users" url="~/admin/users" fornavbar="false"/>
  <pagenode title="events" url="~/admin/events" fornavbar="true"/>
 </pagenode>
 <pagenode title="catalog" url="~/catalog" fornavbar="true"/>
 <pagenode title="contact us" url="~/contactus" fornavbar="false"/>
</pagenode>

now i want to retrieve an xml document for the navbar, which includes all the pagenodes that have fornavbar=true. how can this be done?

the closest i was able to get so far was this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="pagenode[@fornavbar='true']">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>

the problem with this is that includes all the children of anything matched as navbar

i only want to copy all the attributes, not all the children

but if i try

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="pagenode[@fornavbar='true']">
  <pagenode title="{@title}"  url="{@url}"/>
  <xsl:apply-templates/>
 </xsl:template>
</xsl:stylesheet>

then i have 2 problems

  1. i might type out each attribute separately, and i have quite a few per page and theyre apt to change eventually
  2. it loses the hierarchy. everything becomes flat one after the other

i would appreciate all and any help in the matter.

thank you!

EDIT: sample output that id like to see

<pagenode title="home" url="~/" fornavbar="true">
 <pagenode title="events" url="~/admin/events" fornavbar="true"/>
 <pagenode title="catalog" url="~/catalog" fornavbar="true"/>
</pagenode>
5
задан Yisroel M. Olewski 25 January 2011 в 11:44
поделиться