|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: problem with key
Thank you David and Dimitre,
You are both right. Thank you. I would have responded sooner but it took
me some time to find a bug that caused the file to grow. I now pass a
/level/ parameter to facilitate deleting duplicates. Here is working XSLT
<xsl:param name="level"></xsl:param>
<xsl:output method="xml" indent="yes" />
<xsl:variable name="lookupDoc" select="document('step2.xml')"/>
<xsl:key name="SemanticDomainByParent" match="CmSemanticDomain"
use="@parent" />
<xsl:template match="CmSemanticDomain[@level=$level]"/>
<xsl:template match="line[@tag='gd']">
<xsl:variable name="parentSD" select="parent::*/@sd"/>
<SubPossibilities>
<xsl:copy-of select="key('SemanticDomainByParent', $parentSD,
$lookupDoc)"/>
</SubPossibilities>
</xsl:template>
<!-- identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
I ended up building the hierarchy one transformation at a time. The
inserted text has tag = 'gd' which triggers the insertion the next time
around. So multiple application of the same XSL does the trick.
I started by creating a file with just the 0 level of hierarchy. I then
inserted the correct information from an external file at the correct
location. There may be easier ways of doing this. But this is something
that I can explain fairly easily to novices. You continue until you have
processed all the levels.
Thank you again for your help.
Jim Albright
Wycliffe Bible Translators
704-562-1529
On Mon, Apr 12, 2021 at 1:20 AM David Maus lists@xxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> On Mon, 12 Apr 2021 06:08:46 +0200,
> Albright, Jim jim_albright@xxxxxxxxxxxx wrote:
> >
> > [1 <text/plain; UTF-8 (7bit)>]
> > [2 <text/html; UTF-8 (quoted-printable)>]
> > 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>
>
> The quotes around $parentSD look wrong. You are looking up elements
> under the string key '$parentSD'.
>
> I think it should read:
>
> <xsl:copy select="key('SemanticDomainByParent', $parentSD)"/>
>
> HTH,
> -- David
>
> >
> > 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
> > EasyUnsubscribe (by email)
>
> --
> David Maus M.A.
>
> Www: http://dmaus.name
> Twitter: @_dmaus
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








