I have XML files coming in that look like this:
<?xml version='1.0' encoding='UTF-8'?>
<fields>
<field name="customer">
<value>New Customer</value>
</field>
<field name="companyname">
<value>Pagliai's Pizza</value>
</field>
And I want them looking like this:
<field-list>
<field>
<tag>customer</tag>
<value>New Customer</value>
</field>
<field>
<tag>companyname</tag>
<value>Pagliai's PIzza</value>
</field>
This is a case of single-node vs. multiple-node correct? And a XSLT Transform is a "simple" way to do the conversion. Except that it seems everyone using XSLT is using it with PHP or the like and I can't find squat for examples that would work with Switch.
The reason I (think) I want it this way is so I can pull specific values out in Switch as variables. Without the <tag> Switch sees the whole file as one blob.
XSLT Need Help
Re: XSLT Need Help
XLST is hard for me, so I don't really use it. You don't have to transform that to get the values. Here is how to do it with XPath: [Metadata.Text:Path="/fields/field[@name='customer']/value",Dataset="RgpepperXml",Model="XML"]
Here is a flow that writes those values to private data: https://drive.google.com/file/d/0B9ciRz ... sp=sharing
Here is a flow that writes those values to private data: https://drive.google.com/file/d/0B9ciRz ... sp=sharing
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Re: XSLT Need Help
Are these 2 different methods? one for XPath and one using PrivateData?
gabrielp wrote:XLST is hard for me, so I don't really use it. You don't have to transform that to get the values. Here is how to do it with XPath: [Metadata.Text:Path="/fields/field[@name='customer']/value",Dataset="RgpepperXml",Model="XML"]
Here is a flow that writes those values to private data: https://drive.google.com/file/d/0B9ciRz ... sp=sharing
Re: XSLT Need Help
They do different things. Using PD is just a convenient way to access your variables and is considered a best practice. You can read more about it here: https://github.com/open-automation/swit ... guidelines
It boils down to this: what is easier to work with and read?
[Metadata.Text:Path="/fields/field[@name='customer']/value",Dataset="RgpepperXml",Model="XML"]
or
[Job.PrivateData:Key="RGP Customer"]
Perhaps in your flow logic, you wanted to overwrite the customer. Maybe a user would choose a customer within a checkpoint. If you're using PD, you can simply overwrite the "RGP Customer" PD tag and re-route the job. If you're stuck with using the XPath everywhere, you need to re-populate the dataset in the exact same way so your XPath still works.
But the most important reason is, perhaps your dataset changes one day. Maybe you make an update and now the attribute is 'customer_name' instead of 'customer'. Well, if you're using PD, all of your PD values are mapped within a single flow element. So you just update that one element and you're good to go. If you're using the XPath of your external dataset, well you need to update that path in every element, connector, email notification, etc... huge pain.
It boils down to this: what is easier to work with and read?
[Metadata.Text:Path="/fields/field[@name='customer']/value",Dataset="RgpepperXml",Model="XML"]
or
[Job.PrivateData:Key="RGP Customer"]
Perhaps in your flow logic, you wanted to overwrite the customer. Maybe a user would choose a customer within a checkpoint. If you're using PD, you can simply overwrite the "RGP Customer" PD tag and re-route the job. If you're stuck with using the XPath everywhere, you need to re-populate the dataset in the exact same way so your XPath still works.
But the most important reason is, perhaps your dataset changes one day. Maybe you make an update and now the attribute is 'customer_name' instead of 'customer'. Well, if you're using PD, all of your PD values are mapped within a single flow element. So you just update that one element and you're good to go. If you're using the XPath of your external dataset, well you need to update that path in every element, connector, email notification, etc... huge pain.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Re: XSLT Need Help
Thanks for that. But I'm still not tracking if you're saying this _by itself_:
[Metadata.Text:Path="/fields/field[@name='customer']/value",Dataset="RgpepperXml",Model="XML"]
Would accomplish what I'm after, at least in theory.
[Metadata.Text:Path="/fields/field[@name='customer']/value",Dataset="RgpepperXml",Model="XML"]
Would accomplish what I'm after, at least in theory.
Re: XSLT Need Help
What are you after? You want the value of the node with the attribute of "name"? If so, that string will get you that. But only if you conduct an XML Pickup beforehand and name your dataset "RgpepperXml". Please run the flow I made for you if you're unclear.rgpepper wrote:Thanks for that. But I'm still not tracking if you're saying this _by itself_:
[Metadata.Text:Path="/fields/field[@name='customer']/value",Dataset="RgpepperXml",Model="XML"]
Would accomplish what I'm after, at least in theory.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Re: XSLT Need Help
Thanks again Gabe for the clarification, never hurts to have yet another tool in my tool belt - sometimes I just need a one-off piece of data and that will get me there. I will continue to look into your preferred method.
Re: XSLT Need Help
Can you suggest some syntax reference document for this stuff, i.e. how did you know to use "@name="?
Re: XSLT Need Help
I access variables from Metadata > Text > Build location path. I usually just use the GUI which allows you to point and click at which values you want to select. Switch does so in two ways, and the way I'm familiar with is called XPath (https://www.w3.org/TR/xpath/). Sometimes, you want to build a location path with an expression that the Switch GUI doesn't support. In these cases, you can write your own as long as it's XPath 1.0 compatible. You can read more on that here: http://www.enfocus.com/manuals/UserGuid ... th_10.htmlrgpepper wrote:Can you suggest some syntax reference document for this stuff, i.e. how did you know to use "@name="?
This is part of the Metadata module, which you can read about here: http://www.enfocus.com/manuals/UserGuid ... adata.html
But honestly, to answer your question I googled something like "xpath select value from attribute" and found a stackoverflow answer which I adopted in the flow I linked above. I really don't know or like using XML or any of the related standards -- not my thing.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Free Switch apps: open-automation @ Enfocus appstore
Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
Re: XSLT Need Help
Stackoverflow, good stuff. And I agree on XML and its' ilk.