Re: [xslt] Extracting just the value of a property



On Sun, 24 Feb 2008 16:17:34 -0500, Liam R E Quin wrote:

> On Sun, 2008-02-24 at 19:39 +0000, Dan Stromberg wrote:
>> Say you have an xml file like:
>> 
>> <project name="FullDist" default="full">
>>     <property name="projectname" value="Bleeding_Edge"/> <!-- Lots of
>>     other stuff here -->
>> </project>
>> 
>> And you want to pull out just Bleeding_Edge without a lot of xml
>> framing.
>> 
>> >From a shell script, is xsltproc a good way of doing this?  If so how?
> 
> I wrote a simple C program that takes an XML document and an XPath
> expression, and returns the result.  You're welcome to a copy.

Yes, please.  Where might I find it?

> Here it would be, xpath '/project/property[ name="projectname"]/@value'
> 
>> Would xquery be better than XSLT?
> 
> If your document is large, or you're doing it often, yes, probably,
> because then you could have the values indexed, and also because you
> have access to a lot more functions you can call in your XPath
> expressions if you need them.

We aren't using just huge XML documents, nor are we using them in tight 
loops, so perhaps I'll ignore xquery for now.

> As a side-note, this XML design

Sorry, which XML design?  Indexed use of xquery, or your xpath program, 
or something else?

> assumes that neither names nor
> properties ever contain markup themselves, and are always in the same
> language.  If you used sub-elements, you could avoid these constraints,
> e.g.
> 
> <project>
>   <property>
>     <name>The Equation</name>
>     <value>E = mc<sup>2</vaue>
>   </property>
>   <property>
>     <name xml:lang="en">trousers</name>
>     <name xml:lang="en_US">pants</name>
>     <name xml:lang="fr">calsons</name>
>     <value>0</value>
>   </property>
> </project>
> 
> Liam




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]