Subject: Re: [xsl] nesting flat varaible structures? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 23 Sep 2011 16:39:24 -0400 |
I'm trying to use XSLT to do a conversion from one version of the S1000D spec to another. So in the older version you can have this:
<reqpers> <person man="1"/> <perscat category="tech"/> <trade>foo</trade> <person man="2"/> <perscat category="techa"/> <perskill skill="sk05"/> <trade>bar</trade> <esttime>23</esttime> </reqpers>
In the newer version you have a nested structure:
<reqPersons> <person man="1"> <personCategory personCategoryCode="tech"/> <trade>foo</trade> </person> <person man="2"> <personCategory personCategoryCode="techa"/> <personSkill skillLevelCode="sk05"/> <trade>bar</trade> <esttime>23</esttime> </person> <reqPersons>
I can use the following sibling to pull the elements under a new <person> tag, but the problem is that none of the following elements are requried.
I'm working in 2.0. Any ideas on how to correct the results?
~/t/ftemp $ cat dan.xml <?xml version="1.0" encoding="UTF-8"?> <reqpers> <person man="1"/> <perscat category="tech"/> <trade>foo</trade> <person man="2"/> <perscat category="techa"/> <perskill skill="sk05"/> <trade>bar</trade> <esttime>23</esttime> </reqpers> ~/t/ftemp $ xslt2 dan.xml dan.xsl <?xml version="1.0" encoding="UTF-8"?> <reqPersons> <person man="1"> <perscat category="tech"/> <trade>foo</trade> </person> <person man="2"> <perscat category="techa"/> <perskill skill="sk05"/> <trade>bar</trade> <esttime>23</esttime> </person> </reqPersons>~/t/ftemp $ ~/t/ftemp $ cat dan.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="reqpers"> <reqPersons> <!--the following assumes <person> is the first child--> <xsl:for-each-group select="*" group-starting-with="person"> <!--preserve the element--> <xsl:copy> <xsl:copy-of select="@*"/> <!--move sibling elements in the group underneath the first--> <xsl:copy-of select="current-group()[position()>1]"/> </xsl:copy> </xsl:for-each-group> </reqPersons> </xsl:template>
</xsl:stylesheet> ~/t/ftemp $
-- Contact us for world-wide XML consulting and instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] nesting flat varaible str, Echlin, Robert | Thread | Re: [xsl] nesting flat varaible str, Dan Vint |
RE: [xsl] nesting flat varaible str, Echlin, Robert | Date | Re: [xsl] nesting flat varaible str, Liam R E Quin |
Month |