File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes function id() works in the xpath but not in the xsl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "function id() works in the xpath but not in the xsl" Watch "function id() works in the xpath but not in the xsl" New topic
Author

function id() works in the xpath but not in the xsl

Cesar Arend
Greenhorn

Joined: Jan 25, 2013
Posts: 1
Hey I'm from Brazil. So, sorry for my english!

If I consult //jogoGrupo[1]/jogo[1]/selecao/id(@pais) in the xpath I get: Franca e Senegal. However I put this consult int the xsl <xsl:value-of select="//jogoGrupo[1]/jogo[1]/selecao/id(@pais)"/> and doesn't work.


I think the error is in the schema, is it right to declare pais as xs:idref in <selecao pais=s1>, somebody could help me?


XML:



XSL


SCHEMA:

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 462
    
    2
I think the error is in the schema, is it right to declare pais as xs:idref in <selecao pais=s1>, somebody could help me?

There is nothing wrong with the schema. It is just fine to declare pais attribute of selecao as xs:IDREF, you don't have to worry about it. If you define it as so xs:string (taking the most liberal view point), you just sacrifice some tighter constraint during validation: but as far as the schema-aware xslt processor is concerned, when you use fn:id(), it will automatically cast the argument into xs:IDREFS. So as long as those strings are of good format such as no whitespace inside, you could get away with unpredictable results as space would be looked as separator of some IDREF's. In simple term, it is just fine to have it as xs:IDREF.

fn:id() works just fine in xslt 2.0.

Now, what is the problem with your xslt? The problem is that you have not imported the schema to it. The consequence of it is that the xslt processor will fall back to it basic version, rather than being schema-aware and hence fn:id() has no place to do with it as it won't recognize who-is-who xs:ID or xs:IDREF. Or in some technical twist, the is-id property is not populated in the data model.

Furthermore, you can take full schema-awareness to stop xslt to output anything at all, which is often most damaging and non-sense, if the xml is invalid. This is realized in the template I add to it matching the loosely document-node(). This is how you can protect the application from this fallout.

Like that, the application would be quite safe guarding against invalidate xml.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: function id() works in the xpath but not in the xsl
 
Similar Threads
Strings
unexpected child element xs:element error??
Need to create nested element with name
xsd for complex element structure
ID:2 SCJP Question of the day : Thursday June 10 2010