JohnRaffy |
Newbie |
|
Beaver Dam, WisCOWnsin |
Architect/Developer |
|
Male |
|
Monday, May 12, 2014 |
Friday, May 15, 2015 3:59:19 PM |
8 [0.04% of all post / 0.00 posts per day] |
|
Island;
Thank you very much, that gets me going. I'll report back in a week or two with how things work out.
John
|
Let's start from the top with the attached files. My 2nd post was less a "continuation" and more "I tried this but it didn't work..."
The project involves taking the XML Output from an ASME Pressure Vessel Calculation Program (Compress), and translating that to an XML that can be imported by a Product Configurator (DriveWorks).
I've attached the following files:
SampleInput.xml: This is a slimmed down file of the typical output from Compress, and our starting point. PressureVessel.xsd: The Schema file for the above file.
MappingSample.mfd: A very simplified mapping file, showing only a few of the items in the translation, and also including the "known" "Attached To Data"
SampleOutput.xml: the output from the mapping. DriveWorks-Specification.xsd: the Schema file for the output.
The specific problem that I'm trying to address is this:
In a full translation, there are a number of components included. Each of them has an associated "AttachedToID" in their <standardComponentData> Element.
In the sample, I knew the specific <standardComponentData> element I needed to grab data from. In real life, it could be any one of the hundreds of <standardComponentData> elements in the file.
What we need from the "Attached To" item is some dimensional information in order to configure the details of the welded joint.
The XPath to the element I need is //standardComponentData[idNumber=_AttachedToIDNumber_] where _AttachedToIDNumber_ is the value from the <AttachedToidNumber> of the <standardComponentData> being processed.
In the past, I have found this by getting all of the potential <standardComponentData> elements as one Input Sequence to a user Function, and then doing an If Test to see if the ID Numbers matched. This is a pain, and difficult to maintain. (There is a yearly update to the Input Schema, and at least 50% of the time, additional components are added.)
My attempt with the custom XSLT function in my second post was to get a sequence of all of the <standardComponentData> elements, and I got those, but I also got all of the atomic values from the rest of the file.
In addition to the above, I will also need to get the inverse of this search. For example, on the Cylinder that is the Attached To for the Head, I will need to find both the Cylinder's Attached To member, and also items that reference it as the "AttachedToidNumber" In this case, I'll end up with a sequence, and need to filter based on the <AttachedToKind>
Any suggestions or ideas?
I am trying to pickup XPath and XSLT as I go, but we're under the gun to keep things moving.
|
Island;
Thank you for the suggestions, and I will have to see what I can do. As the source, destination and even the definition files, contain proprietary information, both from ourselves and our customers, that may make things difficult. I'll see if I can carve enough out and still have a useful set of files.
The crux of the matter is that while I can get the elements I'm after in the output as XML Elements, I'm also getting all the values from every other element and text.
|
I have been trying to create a Custom XSLT Function, and have come up with the following, which gets all the nodes I'm after in the output file as "nodes", but also includes the remainder of the input file as text interlaced between the nodes.
I am very raw in terms of XSLT, and am faking my way through. I know this not the way to learn a new technology, but any help would be appreciated.
This is the XSLT File:
Code: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="//standardComponentData"> <xsl:for-each select="."> <xsl:call-template name="StandardComponentData"> <xsl:with-param name="ComponentData" select="."/> </xsl:call-template> </xsl:for-each> </xsl:template>
<xsl:template name="StandardComponentData"> <xsl:param name="ComponentData" select="."/> <xsl:copy-of select="."/> </xsl:template>
</xsl:stylesheet>
Here is a snippet of the output I'm getting so far. I need to get rid of the text outside the <standardComponentData> elements. All of the expected <standardComponentData elements are present, just a lot of extraneous garbage, and I don't understand XSLT enough to know why it is there.
Code:
<?xml version="1.0" encoding="UTF-8"?>
0 2014-04-17 U.S. Customary Vertical 192.0000 281.0000 132.9006 <standardComponentData xmlns:cw="urn:xxxx"> <!-- Standard Component Data --> <identifier>Component 1</identifier> <idNumber>1397745764</idNumber> <attachedToidNumber>1397745768</attachedToidNumber> <length units="in">24.3510</length> <designThickness units="in">0.4503</designThickness> </standardComponentData> 1.5000 0.6250 132.0000 <standardComponentData xmlns:cw="urn:xxxx"> <!-- Standard Component Data --> <identifier>Component 2</identifier> <idNumber>1397745768</idNumber> <attachedToidNumber>1397745769</attachedToidNumber> <length units="in">189.0000</length> <designThickness units="in">0.3572</designThickness> </standardComponentData> 1 42.8790 2 94.8185 3 146.7581 English 1033
|
I'm not sure if I have the right topic subject or not, but here's what I'm working with:
I'm working on a translation from one XML file/schema to another XML with a different schema.
The input schema/XML file represents a mechanical assembly with a variable number of different components and sub assembly. Each sub assembly can also have a variable number of components and sub assemblies. This "nesting" can go down several levels deep.
Each component has a schema element that contains Core Data. Part of this Core Data is an "IDNumber" and "AttachedToIDNumber". These values are used to maintain a "many to one" relationship between Components. Each Component can only have one "AttachedToIDNumber", but multiple components can be attached to the same "parent".
What I am hoping to do is the following:
When processing each components Core Data, I want to also gather some of the Core Data from the Core Data of the "Parent Item". I only need some of the key data that can affect the configuration of the "child" component.
I know that one way to do this is to find each occurrence of the Core Data element in the Schema file, and pass them to a User Function that compares that IDNumber to the AttachedToIDNumber of the component being processed, and if they are equal, pass on the Core Data element (and its child elements) to be included.
I am hoping that someone has an easier way than having about 100 instances of a Core Data User Function (some of these "buried" in User Functions), each also requiring about 100 links from all the other Core Data Elements. In essence, is there a way to have a User Function reference, or be given as an input, the entire Input XML file, and find the "Core Data" element that matches the AttachedToIDNumber?
|
I also would like to see a more useful commenting tool. Existing Options, and why they fall short:
* Annotation "Description" on a link ** Short Text Box for entry ** Only Applies/Attaches to the Link ** Does not support multi-line comments (or not well)
* Add a disconnected "Constant" to the mapping as a Comment/Label ** Does not display well, other than for short comments ** Does not support Multi-Line Comments
* Add Annotations as outputs in the Mapping ** Target Schema must support it ** "Constant" display in the Mapping is weak (see above disconnect "Constant"
What would be ideal? I believe Two things (that might be able to be handled as one object):
* The ability to add a Label to the Mapping Display. ** Analogous to a .NET Label ** Selectable Font/Color, etc. ** Manually Placed
* The ability to add a multi-line Text Box (or label) to the Mapping Display ** This would be used for a more robust description of the mapping: *** Descriptions/Notes on the purpose of the Mapping, and what the data "means" ** Traditional Programming/Development Notes *** Notes about Techniques used, or why a particular method was chosen *** Notes for "Future Work", Ideas for Enhancements, etc. *** Revision Notes
MapForce is a powerful programming tool the supports complex development tasks. As such, I believe that we should expect it to have tools similar to other programming languages, including the ability to document the Mapping they way we do other types of source code. Just because we have a "Drag and Drop" interface does not mean the need for developers to document their work has been eliminated.
As a relatively new user involved in a fairly complex project, I've run into more than my share of "learning moments" and frustrations. Even with this in mind, the inability to Comment/Document Mappings and especially Library Functions is the most frustrating thing I have run into.
|
island wrote:HI,
if you are editing the exact same schema files in XML Spy as has been inserted in your Mapforce design, then making a change in the xsd in XML Spy and saving the changes should automatically be recognized by Mapforce i.e. a "changed files" dialog which has a "reload" button will appear in Mapforce. Clicking "reload" will reload the updated schema.
Thank you for the reply.
I was not seeing this behavior, but I will make sure I initiate an edit from within MapForce, and see what happens. I'll report back.
|
Is there a way in MapForce (2014 rel. 2 SP1 (x64)) to have the schema for a input/output component be refreshed/reloaded without closing the map?
I find myself working with files that have namespaces defined, but the Schemas are not available. My workflow ends up something like this:
* Collect some Sample XML Files * Use XMLSpy to Generate a Schema * Start creating a Schema for the Output * Open the two schemas in MapForce and start Mapping * Find a problem in the Generated Schema(s) and/or need to add to or edit the Schema for the Output * While you can use the functionality inside MapForce to "Open File in XML Spy", it appears that you need to close and re-open the map to see the changes.
Is there a way to have the Schemas reflect the changes without closing the Map?
John
|
|