•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the XML, XSLT and XPATH section within the Software Development category of DaniWeb, a massive community of 402,975 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,591 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our XML, XSLT and XPATH advertiser: Programming Forums
Views: 543 | Replies: 1
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I have a problem extracting the information I want from an EMF-model. I have created a meta-Model and from the model (.cim), expressed in XML, I want to generate code in the form of .mof (Managed Object Format). I therefore use XPath to extract information from the model and print it the way I like. But I can't seem to get the information I want...hopefully you can help me.
This is my simple CIM-model expressed in XML:
I want to extract the second value='two' from my first qualifier. Of what I have understood from XPath I tried the following:
<c:get select="/CModel/namespace/classes/qualifiers[1]/value[1]/text()">
But no result is returned. I have also tried many similar variants but everyone including text() fails. I did manage to get the first value from:
<c:get select="/CModel/namespace/classes/qualifiers[1]/@value">
But this implies that 'value' would be an attribute in the XML code, and I still can't get the second value. In the meta model value is expressed as a list of strings (For the qualifier of the type Description it is just a string).
Best regards
-Mats
I have a problem extracting the information I want from an EMF-model. I have created a meta-Model and from the model (.cim), expressed in XML, I want to generate code in the form of .mof (Managed Object Format). I therefore use XPath to extract information from the model and print it the way I like. But I can't seem to get the information I want...hopefully you can help me.
This is my simple CIM-model expressed in XML:
<?xml version="1.0" encoding="UTF-8"?>
<saabgroup:CModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:saabgroup="http://saabgroup.com/cim">
<namespace>
<classes xsi:type="saabgroup:CClass" name="aClass">
<qualifiers xsi:type="saabgroup:CClassConstraint" name="ClassConstraint">
<value>one</value>
<value>two</value>
</qualifiers>
<qualifiers xsi:type="saabgroup:CAbstract" name="Abstract" subclass="Restricted"/>
<qualifiers xsi:type="saabgroup:CDescription" name="Description" value="Desc.">
<translatable/>
</qualifiers>
</classes>
</namespace>
</saabgroup:CModel>I want to extract the second value='two' from my first qualifier. Of what I have understood from XPath I tried the following:
<c:get select="/CModel/namespace/classes/qualifiers[1]/value[1]/text()">
But no result is returned. I have also tried many similar variants but everyone including text() fails. I did manage to get the first value from:
<c:get select="/CModel/namespace/classes/qualifiers[1]/@value">
But this implies that 'value' would be an attribute in the XML code, and I still can't get the second value. In the meta model value is expressed as a list of strings (For the qualifier of the type Description it is just a string).
Best regards
-Mats
•
•
Join Date: Aug 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Hi ,
I think problem is in selecting element <saabgroup:CModel with prefix in the language in which you are trying to extract value.so first you declare name space in your file then use this.. <c:get select="/saabgroup:CModel/namespace/classes/qualifiers[1]/value[2]">
I am not sure because I don't know your language but logically it should work ...
however with xslt...we can extract required value easily by below code :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saabgroup="http://saabgroup.com/cim" version="1.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="saabgroup:CModel">
<xsl:value-of select="namespace/classes/qualifiers[1]/value[2]"/>
</xsl:template>
</xsl:stylesheet>
or
<xsl:template match="/">
<xsl:value-of select="saabgroup:CModel/namespace/classes/qualifiers[1]/value[2]"/>
</xsl:template>
Thanks!
I think problem is in selecting element <saabgroup:CModel with prefix in the language in which you are trying to extract value.so first you declare name space in your file then use this.. <c:get select="/saabgroup:CModel/namespace/classes/qualifiers[1]/value[2]">
I am not sure because I don't know your language but logically it should work ...
however with xslt...we can extract required value easily by below code :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saabgroup="http://saabgroup.com/cim" version="1.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="saabgroup:CModel">
<xsl:value-of select="namespace/classes/qualifiers[1]/value[2]"/>
</xsl:template>
</xsl:stylesheet>
or
<xsl:template match="/">
<xsl:value-of select="saabgroup:CModel/namespace/classes/qualifiers[1]/value[2]"/>
</xsl:template>
Thanks!
![]() |
•
•
•
•
•
•
•
•
DaniWeb XML, XSLT and XPATH Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: avoid self closing tag in the xml file
- Next Thread: Load xml files in a postgre database


Linear Mode