P_YegreS_P Posted December 15, 2011 Share Posted December 15, 2011 Hello, all. I would like to formulate my question in two ways: general and specific. 1) The general formulation. Inside the XSLT file I want to create a kind of classifier that is able to translate some values to other. For example, classifier to convert numbers to their literal value: <classif> <node> <src>1</src> <res>One</res> </node> <node> <src>2</src> <res>Two</res> </node></classif> Where to put such a classifier and how to access it from another part of the XSLT document? 2)The specific formulation.There is a scheme "1.xsd" which contains classifier describing the correspondence between the parameters and their numerical representations (17 = "Option 2" in the example) <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:simpleType name="Name"> <xs:restriction base="xs:string"> <xs:enumeration value="17"> <xs:annotation> <xs:documentation>Option 2</xs:documentation> </xs:annotation> </xs:restriction> </xs:simpleType></xs:schema> To convert "Option 2" to 17 in XSLT, I call them in such way: <xsl:value-of select="document("1.xsd")/xs:schema"/xs:simpleType["Name"]/xs:restriction/xs:enumeration/xs:annotation[xs:documentation="Option 2"]/../@value"/> So, I specify the XSD file name at the beginning of "select" by use of "document()". For some reason, I want to have all the XSLT transformation in a single file. So the question is:How to insert the content of the XSD file (preferably with a minimum modification) in the XSLT file, and then how reference to it? Sincerelly yours,Sergey. P.S. Sorry for my english.P.P.S. I use xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" Link to comment Share on other sites More sharing options...
boen_robot Posted December 15, 2011 Share Posted December 15, 2011 Excluding some quotations marks and the like, your approach should be working. Here's one that should give the same results, while probably working better. <xsl:value-of select="document('1.xsd')/xs:schema/xs:simpleType[@name='Name']/xs:restriction/xs:enumeration[string(xs:annotation/xs:documentation)='Option 2']/@value"/> If you want to put the contents of the XSD file, you'll probably be best off by using the value as above, but then when you need the raw XSD code, use copy-of instead of value-of, like: <xsl:copy-of select="document('1.xsd')/xs:schema/xs:simpleType[@name='Name']/xs:restriction/xs:enumeration[string(xs:annotation/xs:documentation)='Option 2']"/> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.