[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Selection help


Subject: [xsl] Selection help
From: "Joseph L. Casale jcasale@xxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Nov 2015 22:04:16 -0000

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>

Thanks,
jlc


Current Thread
Keywords
xml