0

I am a beginner in XSLT. Could anybody please help me understand how to retrieve an xsd's target namespace in an XSL transformation? I have tried using the document function with the absolute path of the xsd file passed as the parameter but in vain.

All I am trying to achieve is retrieve an xsd's target namespace in an XSL transformation.

this is what I have been using to check if the xsd's in my document are being pushed inot the styelsheet. The count returned is zero that inplies that xsd's are not being fed. Could anybody please help me understand how to I esnure my stylesheet picks up the xsd's in the project directory.Please let me know if you need any further infomration TNS -

Chicky_D
  • 1
  • 2
  • 2
    Show us what you are doing, then we can tell you where you are going wrong. It could be any number of things, for example, namespaces, but we have no way of knowing without seeing your code. – Michael Kay May 05 '14 at 21:34
  • Good morning Mike, I havent arrived at a resolution as yet. However on troubleshooting I found out that the schema document is not being pushed into the stylesheet. As per my understanding the template match(/) ensures that all xml documents in the project directory are pushed into the stylesheet contingent on the pertinent namespaces being present in the stylesheet. – Chicky_D May 09 '14 at 05:26
  • When I run a count() inside the aformentioned template with the root as the paramter (the root of all xml documents is pd:definition), I do score a one corresponding to all the xml files whereas when I do the same inside a template (/xs:schema) I score none and the count remains zero. Could you advise on how to ensure that the xsds are being pushed through the '/' template? I am using eclipse Indigo and/or helios. However the xpath I am using here are fetching me the desired results in any other editor such as Xylus. – Chicky_D May 09 '14 at 05:29
  • @MichaelKay Please find the code in the immediate aforementioned comment. thank you. – Chicky_D May 12 '14 at 04:42
  • So what is "/", the source document of the transformation? If it's a schema, this stylesheet should return "1". – Michael Kay May 12 '14 at 14:07

2 Answers2

1

If you have the XSD schema document, then retrieving the target namespace is as simple as

<xsl:variable name="tns" select="$xsd/xsd:schema/@targetNamespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>

If you're having trouble loading the XSD schema document, then your problem is not getting the target namespace but loading an external document.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
0
    <xsl:variable name="tns" select="string(/xs:schema/@targetNamespace)"/>
    <xsl:message>  TNS
             <xsl:value-of select="$tns" > </xsl:value-of>  
            <xsl:value-of select="/xs:schema/@targetNamespace" >      </xsl:value-of> 
     </xsl:message>
Chicky_D
  • 1
  • 2
  • I get a blank fired when i execute this. However when I carry the same out in an online xslt editor, it yeilds desired results. Seeking your advice. thank you. – Chicky_D May 07 '14 at 09:56
  • @Michael I just figured out that the xsd is not well formed. Could that be a reason? – Chicky_D May 07 '14 at 10:22