Re: [xsl] Selection help

Subject: Re: [xsl] Selection help
From: "Syd Bauman s.bauman@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Nov 2015 22:17:46 -0000
Please be careful ... your sample XSLT is not even well-formed XML!

But I *think* what you're looking for is to execute a template for a
<column> iff its @name is the same as the @name of a
constraint/childKey, yes?  If so,

  <xsl:template match="/root">
    <xsl:apply-templates select="table">
      <xsl:sort/>
    </xsl:apply-templates>
  </xsl:template>
  
  <xsl:template match="table">
    <xsl:apply-templates select="column[@name eq
    current()/constraint[@type='FOREIGN']/childKey/@name]"/>
  </xsl:template>

  <xsl:template match="column">
    <!-- DO STUFF HERE -->
  </xsl:template>

ought to do the trick.

> 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="." />
> 
>       <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>
> 
>       <xsl:for-each select="$columns">
>         <xsl:variable name="foo" select="$this/constraint[@type='FOREIGN']/childKey[@name='.']" />
>         <!-- Test foo, output data if present. -->
>       </xsl:for-each>
>     </xsl:for-each>
>   </xsl:template>
> </xsl:stylesheet>

Current Thread