Re: [xsl] Selection help

Subject: Re: [xsl] Selection help
From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Nov 2015 22:36:52 -0000
On 30 November 2015 at 22:04, Joseph L. Casale
jcasale@xxxxxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
wrote:
> I have some XML similar to:
> <root>
>   <table name="SomeName">
>     <column name="id" type="INTEGER" collate="" nullable="false" />
>     <column name="foo_id" type="INTEGER" collate="" nullable="false" />
>     <column name="bar" type="TEXT" collate="NOCASE" nullable="false" />
>     <constraint type="FOREIGN" parentTable="OtherName" onDelete="CASCADE" onUpdate="CASCADE">
>      <childKey name="foo_id" />
>      <parentKey name="id" />
>     </constraint>
>   </table>
> </root>
>
> For each "table" element, I am iterating through the "column[@name]" values and
> if a "constraint" element with a matching "childKey[@name]" is found, I need to
> perform some conditional logic.
>
> My selector for foo is invalid, I need to select the parent of the matching childKey
> element, however I do not seem to even match the childKey element. Any idea
> as to what I am missing?
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>      xmlns:xs="http://www.w3.org/2001/XMLSchema";>
>   <xsl:output method="text" />
>
>   <xsl:template match=" /root">
>     <xsl:result-document href="result.ext">
>       <xsl:call-template name="result" />
>   </xsl:template>
>
>   <xsl:template name="result">
>
>     <xsl:for-each select="table">
>       <xsl:sort select="." />

there is only one table  so xsl:sort is doing nothing

>
>       <xsl:variable name="this" select="." />
>
>       <xsl:variable name="columns" as="xs:string *">
>         <xsl:for-each select="column">
>           <xsl:value-of select="@name" />
>         </xsl:for-each>
>       </xsl:variable>

That could more simply be written

<xsl:variable name="columns" select="column/string(@name)"/>


>
>       <xsl:for-each select="$columns">
>         <xsl:variable name="foo" select="$this/constraint[@type='FOREIGN']/childKey[@name='.']" />

childKey[@name='.']"

selects childKey elements that have string value of their content
equal to their name attribute.
You presumably meant current() not .

>         <!-- Test foo, output data if present. -->
>       </xsl:for-each>
>     </xsl:for-each>
>   </xsl:template>
> </xsl:stylesheet>
>
> Thanks,
> jlc

Current Thread