Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xsl name spaces - filtering

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 3/3/2009 5:41:00 PM
vanSkier wrote:

> I'm relatively new to xsl and am floundering when trying to access the
> ID and TableID values from the xml below.
> 
> Would the multiple names spaces in the Database node cause any
> problems?


> <Create xmlns="http://schemas.microsoft.com/analysisservices/2003/
> engine">

The Create element has a default namespace declaration that applies to 
the Create element and all its descendant elements so in your XSLT 
stylesheet you need to bind a prefix to that namespace and use that 
prefix in XPath expressions and match patterns to a select/match 
elements. See below.

>   <ObjectDefinition>
>     <Database xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>       <ID>Insight_Budget</ID>
>       <Dimensions>
>         <Dimension>
>           <ID>Tbl Dim Division</ID>
>           <Name>Division</Name>
>           <Attributes>
>             <Attribute>
>               <ID>Level0 Name</ID>
>               <Name>Division Level0 Name</Name>
>               <Usage>Key</Usage>
>               <EstimatedCount>39</EstimatedCount>
>               <KeyColumns>
>                 <KeyColumn>
>                   <DataType>WChar</DataType>
>                   <DataSize>80</DataSize>
>                   <Source xsi:type="ColumnBinding">
>                     <TableID>dbo_tblDimDivision</TableID>
>                     <ColumnID>Level0_Name</ColumnID>
>                   </Source>
>                 </KeyColumn>
>               </KeyColumns>
>             </Attribute>
>           </Attributes>
>         </Dimension>
>       </Dimensions>
>     </Database>
>   </ObjectDefinition>
> </Create>


> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
> Transform" xmlns:xlink_01="http://schemas.microsoft.com/
> analysisservices/2003/engine" xmlns:xlink_02="http://www.w3.org/2001/
> XMLSchema" >

So you have correctly bound a prefix ('xlink_01') to the default 
namespace but
> <xsl:template match="/">
> 
> <HTML>
> <BODY>
> 	<xsl:apply-templates select="//xlink_01:Create"/>
>   <xsl:apply-templates select="//xlink_01:Create/ObjectDefinition/
> Database/Dimensions/Dimension/ID"/>

here you fail to apply that prefix consistently to all elements e.g.
   <xsl:apply-templates 
select="/xlink_01:Create/xlink_01:ObjectDefinition/xlink_01:Database/xlink_01:Dimensions/xlink_01:Dimension/xlink_01:ID"/>

>   <xsl:apply-templates select="//xlink_01:Create/ObjectDefinition/
> xlink_02:Database/Dimensions/Dimension/ID"/>
>   <xsl:apply-templates select="//Create/ObjectDefinition/Database/
> Dimensions/Dimension/ID"/>
>   <xsl:apply-templates select="ID"/>
>   <xsl:apply-templates select="//xlink_01:Create/ObjectDefinition/
> Database/Dimensions/Dimension/Attributes/Attribute/KeyColumns/
> KeyColumn/Source/TableID"/>

Make the same changes for all those XPath expressions above.

> </BODY>
> </HTML>
> </xsl:template>
> 
> 
>   <xsl:template match="//xlink_01:Create">

     <xsl:template match="xlink_01:Create">
suffices, but that is only a minor issue not related to the other 
problem explained above.

>     <B>
>       <xsl:text>This works: </xsl:text>
>       <xsl:value-of select="local-name()" />
>     </B>
>   </xsl:template>
> 
> 
>   <xsl:template match="ID">

You need
     <xsl:template match="xlink_01:ID">

>     <B>
>       <xsl:value-of select="local-name()" />
>     </B>
>   </xsl:template>
> 
> 
>   <xsl:template match="TableID">

and
     <xsl:template match="xlink_01:TableID">

> 	  <B><xsl:value-of select="local-name()" /></B>
>   </xsl:template>
> 
> 
> </xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent