Re: [xsl] nesting flat varaible structures?

Subject: Re: [xsl] nesting flat varaible structures?
From: Liam R E Quin <liam@xxxxxx>
Date: Fri, 23 Sep 2011 16:53:30 -0400
On Fri, 2011-09-23 at 12:25 -0700, dvint@xxxxxxxxx wrote:
> 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>

Although it's a grouping problem I'd quite likely (depending on the
actual schemas) have a template to match person that looked ahead and
called apply-templates on the following elements in a mode, and have
templates e.g. for trade, that were empty --

<xsl:template match="trade|perskill|esttime" />
<xsl:template match="trade" mode="nested">
    <xsl:copy-of select="."/> <!--* or whatever *-->
</xsl:template>

I see this is similar to your approach, so...
> 
> 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.
> So this will work if I have a consistent combination of elements.
> 
> <xsl:template match="person">
> <person>
>   <xsl:call-template name="processSecurityAttributes"/>
>   <xsl:call-template name="processsChangeAttributes"/>
>   <xsl:call-template name="processsIDAttributes"/>
>   <xsl:call-template name="processsApplicabilityAttributes"/>
>   <xsl:if test="@man">
>     <xsl:attribute name="man" select="@man"/>
>   </xsl:if>

You can do all those at once with a mode:
    <xsl:apply-templates
        select="processSecurityAttribuets|removeSocks"
        mode="my-happy-person-mode" />

Then you don't need the for-eaches you're using.

For the two-person-elements question you need to say what you want to
happen in that case bfore anyone can help you with it :-)

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/

Current Thread