473,698 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT and XPath lookup problem

I am trying to implement a better method than I already have to document
database schemas with XML, and use XSLT to both generate database DDL
statements (CREATE TABLE, etc) and to transform to HTML for documentation
purposes. In particular I want XSLT to transform to HTML so that my XML
documents can be "live", doing the transform in the browser.

In the new system a very short XML document looks like:

<database>
<table id="PROVIDER">
<field name="KEY" type="decimal" precision="9" scale="0"/>
...
<primary-key id="PKPROVIDER " fields="KEY"/>
</table>

<table id="PERSON">
<field name="PROVIDER"/>
<field name="KEY" type="decimal" precision="9" scale="0"/>
...
<primary-key id="PKPERSON" fields="PROVIDE R KEY"/>
<foreign-key id="FKPERSON" fields="PROVIDE R" foreign-table="PROVIDER "
on-delete="cascade " on-update="restric t"/>
</table>
</database>

Short description would be:

PROVIDER - a table
PROVIDER.KEY decimal(9,0) (is primary key, so not-null and unique).
Primary key is PROVIDER.KEY

PERSON - a table
PERSON.PROVIDER is foreign key to PROVIDER.KEY, so is same data type.
PERSON.KEY decimal(9,0) is unique number within provider.
Primary key is PERSON.PROVIDER and PERSON.KEY
Foreign key to the PROVIDER table where PERSON.PROVIDER = PROVIDER.KEY

Note that PERSON.PROVIDER doesn't have any type,etc attributes. Since
PERSON.PROVIDER is actually a foreign key to the PROVIDER.KEY field, the
two fields need to have the same data type, and when generating DDL, etc
the data type should be looked up from the field that this foreign field
references. Therefore PERSON.PROVIDER 's data type should be listed as the
same as PROVIDER.KEY's type,precision, etc. A "gotcha" is that
PERSON.PROVIDER could possibly be listed in more than one foreign-key
element, so I'd have to only follow the first one found.

I'm trying to write a template (mode="datatype ") for a field node which
outputs the actual type,precision, length,etc values for a field. In the
case of PROVIDER.KEY that's easy, because it is explicitly defined by the
attributes for the node. But for PERSON.PROVIDER I can't figure it out. So
far my template looks like:

<xsl:template match="field" mode="datatype" >
<xsl:choose>
<!-- If type is present, go ahead with the data type -->
<xsl:when test="@type">
<xsl:choose>
<!-- If length present, write out type(length) -->
<xsl:when test="@length"> <xsl:value-of
select="@type"/>(<xsl:value-of select="@length "/>)</xsl:when>
<xsl:when test="@precisio n">
<!-- If precision is present... -->
<xsl:choose>
<!-- If scale is also present, write out type(precision, scale)
-->
<xsl:when test="@scale">< xsl:value-of
select="@type"/>(<xsl:value-of select="@precis ion"/>,<xsl:value-of
select="@scale"/>)</xsl:when>
<!-- Otherwise write out type(precision) -->
<xsl:otherwise> <xsl:value-of select="@type"/>(<xsl:value-of
select="@precis ion"/>)</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- No length,precisio n,scale - write out type -->
<xsl:otherwise> <xsl:value-of select="@type"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Otherwise, assume it is a foreign key and use the foreign field
instead -->
<xsl:otherwis e>
????????????
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Any help appreciated.

Jul 20 '05 #1
1 4013
Use:

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="table">
<xsl:value-of select="concat( '&#xA;', @id, ' - a table')"/>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="field" >

<xsl:variable name="vRefTable "
select="/*/table[@id
= current()/../foreign-key
[@fields=current ()/@name]
/@foreign-table
]"/>

<xsl:variable name="vRef"
select="self::*[@type]
|
$vRefTable/field
[@name
=
$vRefTable/primary-key/@fields
]"/>

<xsl:value-of select="concat( @name, ' ')"/>
<xsl:choose>
<!-- If length present, write out type(length) -->
<xsl:when test="$vRef/@length">
<xsl:value-of select="$vRef/@type"/>
<xsl:value-of select="concat( '(',$vRef/@length, ')')"/>
</xsl:when>
<xsl:when test="$vRef/@precision">
<!-- If precision is present... -->
<xsl:choose>
<!-- If scale is also present, write out type(precision, scale)
-->
<xsl:when test="$vRef/@scale">
<xsl:value-of select="$vRef/@type"/>
<xsl:value-of select="concat( '(',$vRef/@precision, ',',
$vRef/@scale,')')"/>
</xsl:when>
<!-- Otherwise write out type(precision) -->
<xsl:otherwis e>
<xsl:value-of select="$vRef/@type"/>
<xsl:value-of select="concat( '(', $vRef/@precision, ')')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- No length,precisio n,scale - write out type -->
<xsl:otherwis e>
<xsl:value-of select="$vRef/@type"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
When this transformation is applied on your source.xml:

<database>
<table id="PROVIDER">
<field name="KEY" type="decimal" precision="9" scale="0"/>
<primary-key id="PKPROVIDER " fields="KEY"/>
</table>
<table id="PERSON">
<field name="PROVIDER"/>
<field name="KEY" type="decimal" precision="9" scale="0"/>
<primary-key id="PKPERSON" fields="PROVIDE R KEY"/>
<foreign-key id="FKPERSON" fields="PROVIDE R" foreign-table="PROVIDER "
on-delete="cascade " on-update="restric t"/>
</table>
</database>

the wanted result is produced:

PROVIDER - a table
KEY decimal(9,0)

PERSON - a table
PROVIDER decimal(9,0)
KEY decimal(9,0)

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Patrick Reilly" <pd*@localhost. localdomain> wrote in message
news:2p******** ************@fe ed2.centurytel. net...
I am trying to implement a better method than I already have to document
database schemas with XML, and use XSLT to both generate database DDL
statements (CREATE TABLE, etc) and to transform to HTML for documentation
purposes. In particular I want XSLT to transform to HTML so that my XML
documents can be "live", doing the transform in the browser.

In the new system a very short XML document looks like:

<database>
<table id="PROVIDER">
<field name="KEY" type="decimal" precision="9" scale="0"/>
...
<primary-key id="PKPROVIDER " fields="KEY"/>
</table>

<table id="PERSON">
<field name="PROVIDER"/>
<field name="KEY" type="decimal" precision="9" scale="0"/>
...
<primary-key id="PKPERSON" fields="PROVIDE R KEY"/>
<foreign-key id="FKPERSON" fields="PROVIDE R" foreign-table="PROVIDER "
on-delete="cascade " on-update="restric t"/>
</table>
</database>

Short description would be:

PROVIDER - a table
PROVIDER.KEY decimal(9,0) (is primary key, so not-null and unique).
Primary key is PROVIDER.KEY

PERSON - a table
PERSON.PROVIDER is foreign key to PROVIDER.KEY, so is same data type.
PERSON.KEY decimal(9,0) is unique number within provider.
Primary key is PERSON.PROVIDER and PERSON.KEY
Foreign key to the PROVIDER table where PERSON.PROVIDER = PROVIDER.KEY

Note that PERSON.PROVIDER doesn't have any type,etc attributes. Since
PERSON.PROVIDER is actually a foreign key to the PROVIDER.KEY field, the
two fields need to have the same data type, and when generating DDL, etc
the data type should be looked up from the field that this foreign field
references. Therefore PERSON.PROVIDER 's data type should be listed as the
same as PROVIDER.KEY's type,precision, etc. A "gotcha" is that
PERSON.PROVIDER could possibly be listed in more than one foreign-key
element, so I'd have to only follow the first one found.

I'm trying to write a template (mode="datatype ") for a field node which
outputs the actual type,precision, length,etc values for a field. In the
case of PROVIDER.KEY that's easy, because it is explicitly defined by the
attributes for the node. But for PERSON.PROVIDER I can't figure it out. So
far my template looks like:

<xsl:template match="field" mode="datatype" >
<xsl:choose>
<!-- If type is present, go ahead with the data type -->
<xsl:when test="@type">
<xsl:choose>
<!-- If length present, write out type(length) -->
<xsl:when test="@length"> <xsl:value-of
select="@type"/>(<xsl:value-of select="@length "/>)</xsl:when>
<xsl:when test="@precisio n">
<!-- If precision is present... -->
<xsl:choose>
<!-- If scale is also present, write out type(precision, scale)
-->
<xsl:when test="@scale">< xsl:value-of
select="@type"/>(<xsl:value-of select="@precis ion"/>,<xsl:value-of
select="@scale"/>)</xsl:when>
<!-- Otherwise write out type(precision) -->
<xsl:otherwise> <xsl:value-of select="@type"/>(<xsl:value-of
select="@precis ion"/>)</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- No length,precisio n,scale - write out type -->
<xsl:otherwise> <xsl:value-of select="@type"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Otherwise, assume it is a foreign key and use the foreign field
instead -->
<xsl:otherwis e>
????????????
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Any help appreciated.

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2919
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
4
21206
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a native English speaker, it's quite hard to make the problem clear. Please see the following example.
4
1829
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
3
4540
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method should result in a NodeSet". Of course, that (sort of) makes sense to me now (I suppose just an attribute couldn't be a nodeset, but how would I go
2
1641
by: Pawel | last post by:
I have small problem with XslTransformation. I get from WebService xml document. I have xslt and I want transform xml document to html code. It's look easy but I cant't manage with xPath. Maybe someone help me with that. I have problems with xPath in xslt file. I can't navigate by names only by vertical and horizontal axis. What's wrong .... --- Code --- // WebService XmlForAnalysis.Xmla xa = new XmlForAnalysis.Xmla(); xa.Url =...
3
3090
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION> <OPTION>3<OPTION> </FIELD>
1
2415
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT stylesheets, that generates .NET assemblies) 2. Performance improvements in the XslCompiledTransform
3
9590
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
2
22771
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most common usage of this is in creating hyperlinks.
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.