Re: [xsl] problem with key

Subject: Re: [xsl] problem with key
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 12 Apr 2021 04:25:00 -0000
 >       <SubPossibilities>
 >             <xsl:copy select="key('SemanticDomainByParent',
'$parentSD')"/>
   >       </SubPossibilities>

I think you want to use *<xsl:copy-of>* here, and the XSLT processor
probably should have raised an error.


Cheers,
Dimitre

On Sun, Apr 11, 2021 at 9:08 PM Albright, Jim jim_albright@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> I am trying to upconvert from a flat-file. After I get it into XML form I
> try to add hierarchy using "key".
> -------------
> OUTPUT
> -------------
> I get NO results from
> <SubPossibilities>
>             <xsl:copy select="key('SemanticDomainByParent', '$parentSD')"/>
> </SubPossibilities>
>
> so output looks like
> <SubPossibilities/>
>
> So what am I doing wrong?
>
>
> Starting with this XML
> -------------
> XML input
> -------------
>
> ...      <Possibilities>
>          <CmSemanticDomain level="1"      sd="1"   parent=""
> guid="I63403699-07C1-43F3-A47C-069D6E4316E5">
>             <line tag="sd">Universe, creation</line>
>             <line tag="gd">I63403699-07C1-43F3-A47C-069D6E4316E5</line>
>          </CmSemanticDomain>
>          <CmSemanticDomain level="2"  sd="1.1"   parent="1"
> guid="I999581C4-1611-4ACB-AE1B-5E6C1DFE6F0C">
>                <line tag="sd">Sky</line>
>                <line tag="gd">I999581C4-1611-4ACB-AE1B-5E6C1DFE6F0C</line>
>           </CmSemanticDomain>
>          <CmSemanticDomain level="3"   sd="1.1.1"    parent="1.1"
> guid="IDC1A2C6F-1B32-4631-8823-36DACC8CB7BB">
>             <line tag="sd">Sun</line>
>             <line tag="gd">IDC1A2C6F-1B32-4631-8823-36DACC8CB7BB</line>
>          </CmSemanticDomain>
>          <CmSemanticDomain level="4"  sd="1.1.1.1"    parent="1.1.1"
> guid="I1BD42665-0610-4442-8D8D-7C666FEE3A6D">
>             <line tag="sd">Moon</line>
>             <line tag="gd">I1BD42665-0610-4442-8D8D-7C666FEE3A6D</line>
>          </CmSemanticDomain>
>          <CmSemanticDomain level="4"  sd="1.1.1.2"  parent="1.1.1"
> guid="IB044E890-CE30-455C-AEDE-7E9D5569396E">
>             <line tag="sd">Star</line>
>             <line tag="gd">IB044E890-CE30-455C-AEDE-7E9D5569396E</line>
>          </CmSemanticDomain>
>          <CmSemanticDomain level="4"  sd="1.1.1.3"   parent="1.1.1"
> guid="IA0D073DF-D413-4DFD-9BA1-C3C68F126D90">
>             <line tag="sd">Planet</line>
>             <line tag="gd">IA0D073DF-D413-4DFD-9BA1-C3C68F126D90</line>
>          </CmSemanticDomain>
>
> ...
> -------------
> XSL
> -------------
> ...
>   <xsl:key name="SemanticDomainByParent" match="CmSemanticDomain"
> use="@parent" />
>
>     <xsl:template match="CmSemanticDomain">
>         <CmSemanticDomain>
>             <xsl:apply-templates select="@* | node()"/>
>             <xsl:apply-templates
> select="key('SemanticDomainByParent',@sd)"/>
>         </CmSemanticDomain>
>     </xsl:template>
>
>     <xsl:template match="line[@tag='gd']">
>         <xsl:variable name="parentSD" select="parent::*/@parent"/>
>         <SubPossibilities>
>             <xsl:copy select="key('SemanticDomainByParent', '$parentSD')"/>
>         </SubPossibilities>
>     </xsl:template>
>
>     <!-- identity transform -->
>     <xsl:template match="@* | node()">
>         <xsl:copy>
>             <xsl:apply-templates select="@* | node()"/>
>         </xsl:copy>
>     </xsl:template>
>
>
> -------------
> Desired OUTPUT
> -------------
> ...
>       <Possibilities>
>          <CmSemanticDomain level="1"      sd="1"   parent=""
> guid="I63403699-07C1-43F3-A47C-069D6E4316E5">
>                <line tag="sd">Universe, creation</line>
>                <SubPossibilities>
>                   <CmSemanticDomain level="2"  sd="1.1"   parent="1"
> guid="I999581C4-1611-4ACB-AE1B-5E6C1DFE6F0C">
>                        <line tag="sd">Sky</line>
>                       <SubPossibilities>
>                           <CmSemanticDomain level="3"   sd="1.1.1"
> parent="1.1"    guid="IDC1A2C6F-1B32-4631-8823-36DACC8CB7BB">
>                               <line tag="sd">Sun</line>
>                               <SubPossibilities>
>                                   <CmSemanticDomain level="4"
> sd="1.1.1.2"  parent="1.1.1"  guid="IB044E890-CE30-455C-AEDE-7E9D5569396E">
>                                       <line tag="sd">Star</line>
>                                   </CmSemanticDomain>
>                                   <CmSemanticDomain level="4"
> sd="1.1.1.3"   parent="1.1.1"
> guid="IA0D073DF-D413-4DFD-9BA1-C3C68F126D90">
>                                        <line tag="sd">Planet</line>
>                                  </CmSemanticDomain>
> ...
>                              </SubPossibilities>
>                          </CmSemanticDomain>
>                       </SubPossibilities>
>                   </CmSemanticDomain>
>               </SubPossibilities>
>           </CmSemanticDomain>
>       </Possibilities>
>
>
> Jim Albright
> Wycliffe Bible Translators
> 704-562-1529
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
> email <>)
>


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread