[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Unable to select wanted nodes

Subject: Re: Unable to select wanted nodes
From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 6 Oct 2011 19:09:52 -0400
Re:  Unable to select wanted nodes
Sorry, folks, responded to the wrong message.

Ken had pointed out to me off-list that the use of "name(@*)" will
throw an error in XSLT 2.0 if there is more than one attribute on the
element.  While the input data, in this case, appears to always have
only one attribute, it's not clear whether or not this is ensured by a
schema.  The error thrown in the case where there is more than one
attribute might be seen as a type of validation check, but probably
not a very good or helpful one.  Point is, this is a somewhat
dangerous construct to use without some checks to ensure there aren't
multiple attributes.

Thanks, Ken, for the tip, and my apologies again for the misdirected
reply (though I still would like to know about the new course!).

-Brandon :)


On Thu, Oct 6, 2011 at 7:03 PM, Brandon Ibach
<brandon.ibach@xxxxxxxxxxxxxxxxxxx> wrote:
> Hi, Ken...
>
> This is a good point.  I wasn't aware that this would throw an error
> in 2.0, but for what it's worth, that might really be desired
> behavior, anyway.  His model seems to be that the element in question
> should only ever have one attribute.  I don't know if he's using any
> kind of schema to enforce that, but if he isn't, then the error thrown
> by the transform would essentially be a (admittedly clunky, likely
> with a not-very-helpful error message) form of validation check.
>
> In any case, it might be worth explaining the detail, for the archives.
>
> I've been meaning to ask, what's the new course you mentioned working
> on recently?
>
> -Brandon :)
>
>
> On Thu, Oct 6, 2011 at 4:02 PM, Mark <mark@xxxxxxxxxxxx> wrote:
>> For the below <Input> file, I want the <DesiredOutput> file but so far I
>> have only been able to write code that produces <MyOutput>.
>>
>> In <MyOutPut>:
>> (1) The mode="stamp" templates produce satisfactory <StampPage> elements.
>> These templates and their output were included only for completeness and
may
>> be ignored.
>>
>> (2) The mode="formats" templates produce the <FormatPage> and its child
>> <StampButtons> properly, but I cannot puzzle out how to produce the
children
>> of <FormatButtons>.  I am not even sure that what I have done so far is
the
>> best way to do this.
>>
>> Side note: the redundant attribute in the <FormatPage> element appears
>> solely as debugging aid.
>>
>> Help graciously accepted,
>> Mark
>>
>> <Input>
>>   <Set>
>>     <Stamp>
>>       <CatNumbers pofis-number="105"/>
>>       <Formats souvenir-sheet="105"/>
>>       <Formats se-tenant="105"/>
>>     </Stamp>
>>     <Stamp>
>>       <CatNumbers pofis-number="106"/>
>>       <Formats souvenir-sheet="105"/>
>>       <Formats se-tenant="105"/>
>>     </Stamp>
>>     <Stamp>
>>       <CatNumbers pofis-number="107"/>
>>       <Formats souvenir-sheet="105"/>
>>       <Formats se-tenant="107"/>
>>     </Stamp>
>>     <Stamp>
>>       <CatNumbers pofis-number="108"/>
>>       <Formats souvenir-sheet="105"/>
>>       <Formats se-tenant="107"/>
>>     </Stamp>
>>   </Set>
>>  </Input>
>> ----------------
>> <DesiredOutput>
>>   <StampPage>
>>     <FormatButtons>
>>       <Formats state="active" souvenir-sheet="105"/>
>>       <Formats state="active" se-tenant="105"/>
>>     </FormatButtons>
>>     <StampButtons>
>>       <Stamp state="depressed" pofis-number="105"/>
>>     </StampButtons>
>>   </StampPage>
>>   <StampPage>
>>     <FormatButtons>
>>       <Formats state="active" souvenir-sheet="105"/>
>>       <Formats state="active" se-tenant="105"/>
>>     </FormatButtons>
>>     <StampButtons>
>>       <Stamp state="depressed" pofis-number="106"/>
>>     </StampButtons>
>>   </StampPage>
>>   <StampPage >
>>     <FormatButtons>
>>       <Formats state="active" souvenir-sheet="105"/>
>>       <Formats state="active" se-tenant="107"/>
>>     </FormatButtons>
>>     <StampButtons>
>>       <Stamp state="depressed" pofis-number="107"/>
>>     </StampButtons>
>>   </StampPage>
>>   <StampPage>
>>     <FormatButtons>
>>       <Formats state="active" souvenir-sheet="105"/>
>>       <Formats state="active" se-tenant="107"/>
>>     </FormatButtons>
>>     <StampButtons>
>>       <Stamp state="depressed" pofis-number="108"/>
>>     </StampButtons>
>>   </StampPage>
>>   <FormatPage souvenir-sheet="105">
>>     <FormatButtons>
>>       <Formats state="depressed" souvenir-sheet="105"/>
>>       <Formats label="1" state="active" se-tenant="105"/>
>>       <Formats label="2" state="active" se-tenant="107"/>
>>     </FormatButtons>
>>     <StampButtons>
>>       <Stamp label="1" state="active" pofis-number="105"/>
>>       <Stamp label="2" state="active" pofis-number="106"/>
>>       <Stamp label="3" state="active" pofis-number="107"/>
>>       <Stamp label="4" state="active" pofis-number="108"/>
>>     </StampButtons>
>>   </FormatPage>
>>   <FormatPage se-tenant="105">
>>     <FormatButtons>
>>       <Formats state="active" souvenir-sheet="105"/>
>>       <Formats label="1" state="depressed" se-tenant="105"/>
>>       <Formats label="2" state="active" se-tenant="107"/>
>>     </FormatButtons>
>>     <StampButtons>
>>       <Stamp label="1" state="active" pofis-number="105"/>
>>       <Stamp label="2" state="active" pofis-number="106"/>
>>     </StampButtons>
>>   </FormatPage>
>>   <FormatPage se-tenant="107">
>>     <FormatButtons>
>>       <Formats state="active" souvenir-sheet="105"/>
>>       <Formats label="1" state="active" se-tenant="105"/>
>>       <Formats label="2" state="depressed" se-tenant="107"/>
>>     </FormatButtons>
>>     <StampButtons>
>>       <Stamp label="1" state="active" pofis-number="107"/>
>>       <Stamp label="2" state="active" pofis-number="108"/>
>>     </StampButtons>
>>   </FormatPage>
>>  </DesiredOutput>
>>
>> -------------------
>> <MyOutput>
>>  <StampPage>
>>   <FormatButtons>
>>     <Formats state="active" souvenir-sheet="105"/>
>>     <Formats state="active" se-tenant="105"/>
>>   </FormatButtons>
>>   <StampButtons>
>>     <Stamp state="depressed" pofis-number="105"/>
>>   </StampButtons>
>>  </StampPage>
>>  <StampPage>
>>   <FormatButtons>
>>     <Formats state="active" souvenir-sheet="105"/>
>>     <Formats state="active" se-tenant="105"/>
>>   </FormatButtons>
>>   <StampButtons>
>>     <Stamp state="depressed" pofis-number="106"/>
>>   </StampButtons>
>>  </StampPage>
>>  <StampPage>
>>   <FormatButtons>
>>     <Formats state="active" souvenir-sheet="105"/>
>>     <Formats state="active" se-tenant="107"/>
>>   </FormatButtons>
>>   <StampButtons>
>>     <Stamp state="depressed" pofis-number="107"/>
>>   </StampButtons>
>>  </StampPage>
>>  <StampPage>
>>   <FormatButtons>
>>     <Formats state="active" souvenir-sheet="105"/>
>>     <Formats state="active" se-tenant="107"/>
>>   </FormatButtons>
>>   <StampButtons>
>>     <Stamp state="depressed" pofis-number="108"/>
>>   </StampButtons>
>>  </StampPage>
>>  <FormatPage souvenir-sheet="105">
>>   <FormatButtons>
>>     <!-- My problem -->
>>   </FormatButtons>
>>   <StampButtons>
>>     <Stamp label="1" state="active" pofis-number="105"/>
>>     <Stamp label="2" state="active" pofis-number="106"/>
>>     <Stamp label="3" state="active" pofis-number="107"/>
>>     <Stamp label="4" state="active" pofis-number="108"/>
>>   </StampButtons>
>>  </FormatPage>
>>  <FormatPage se-tenant="105">
>>   <FormatButtons>
>>     <!-- My problem -->
>>   </FormatButtons>
>>   <StampButtons>
>>     <Stamp label="1" state="active" pofis-number="105"/>
>>     <Stamp label="2" state="active" pofis-number="106"/>
>>   </StampButtons>
>>  </FormatPage>
>>  <FormatPage se-tenant="107">
>>   <FormatButtons>
>>     <!-- My problem -->
>>   </FormatButtons>
>>   <StampButtons>
>>     <Stamp label="1" state="active" pofis-number="107"/>
>>     <Stamp label="2" state="active" pofis-number="108"/>
>>   </StampButtons>
>>  </FormatPage>
>> </MyOutput>
>>
>> ------------------------
>> Stylesheet:
>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xs
>> xd"
>>  version="2.0">
>>
>>  <xsl:strip-space elements="*"/>
>>
>>  <xsl:template match="Set">
>>   <xsl:element name="Output">
>>     <xsl:apply-templates mode="stamp"/>
>>     <xsl:apply-templates mode="formats"/>
>>   </xsl:element>
>>  </xsl:template>
>>
>>  <!-- Create a StampPage for every Stamp -->
>>  <xsl:template match="Stamp" mode="stamp">
>>   <xsl:element name="StampPage">
>>     <xsl:element name="FormatButtons">
>>       <xsl:apply-templates mode="stamp"/>
>>     </xsl:element>
>>     <xsl:element name="StampButtons">
>>       <xsl:element name="Stamp">
>>         <xsl:attribute name="state" select="'depressed'"/>
>>         <xsl:attribute name="pofis-number"
>> select="CatNumbers/@pofis-number"/>
>>       </xsl:element>
>>     </xsl:element>
>>   </xsl:element>
>>  </xsl:template>
>>
>>  <xsl:template match="Stamp" mode="formats">
>>   <xsl:apply-templates mode="formats"/>
>>  </xsl:template>
>>
>>  <xsl:template match="Formats" mode="stamp">
>>   <xsl:element name="Formats">
>>     <xsl:attribute name="state" select="'active'"/>
>>     <xsl:copy-of select="@*"/>
>>   </xsl:element>
>>  </xsl:template>
>>
>>  <xsl:template match="Formats" mode="formats">
>>   <xsl:if test="@* eq ../CatNumbers/@pofis-number">
>>     <xsl:element name="FormatPage">
>>       <xsl:copy-of select="@*"/>
>>       <xsl:variable name="format" select="name(@*)"/>
>>       <xsl:variable name="number" select="@*"/>
>>       <xsl:element name="FormatButtons">
>>        <!-- I do not know how to select the correct components -->
>>       </xsl:element>
>>       <xsl:element name="StampButtons">
>>         <xsl:choose>
>>           <xsl:when test="count(../../Stamp/Formats/@*[name(.)=$format])
eq
>> 1">
>>             <xsl:element name="Stamp">
>>               <xsl:attribute name="state" select="'active'"/>
>>               <xsl:copy-of select="../CatNumbers/@pofis-number"/>
>>             </xsl:element>
>>           </xsl:when>
>>           <xsl:otherwise>
>>             <xsl:for-each-group select="../../Stamp/Formats"
>> group-by="@*[name(.)=$format]">
>>               <xsl:for-each select="current-group()">
>>                 <xsl:if test="@* eq $number">
>>                   <xsl:element name="Stamp">
>>                     <xsl:attribute name="label" select="position()"/>
>>                     <xsl:attribute name="state" select="'active'"/>
>>                     <xsl:copy-of select="../CatNumbers/@pofis-number"/>
>>                   </xsl:element>
>>                 </xsl:if>
>>               </xsl:for-each>
>>             </xsl:for-each-group>
>>           </xsl:otherwise>
>>         </xsl:choose>
>>       </xsl:element>
>>     </xsl:element>
>>   </xsl:if>
>>  </xsl:template>
>>
>> </xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.