This is similar to this XSLT question, but ultimately for DWT.
We can get a keyword's key via a C# TBB.
ItemFields fields = new ItemFields(component.Metadata, component.Schema);
KeywordField keywordField = fields["state"] as KeywordField;
String stateValue = package.EvaluateExpression("Component.Metadata.state");
package.PushItem("statekey", package.CreateStringItem(ContentType.Text, keywordField.Value.Key));
In DWT, I sometimes want the key of a selected keyword in a component.
Is adding and getting these from the package the correct approach?
##Component.Metadata.State## gets me the value. Referencing the key directly from DWT would be great, but I haven't seen anything to suggest DWT exposes it.
As another alternative to John's answer. How about taking a similar approach to Will's "Get Component Template Uris" and write a TBB that iterates over a category's keywords and writes them out into the package with the desired output value? You'd then be able to use these values directly from DWT with a "double-evaluation" like:
##Keyword${Component.Metadata.state}Value##
I suspect for this you would need to go down the TBB route as you suggest, or even write your own DWT function to expose it.
You can find an example of creating DWT functions here: http://www.tridiondeveloper.com/get-and-set-variables-in-dwts
Related
I am trying to put multiple values inside this content with this XQuery Expression Builder. I tried to use a string function like thisfn:concat($body, $inbound, $inbound), but this does not seems to keep the whole message.
Is there any way that I can put all these variables in one report action? If this is possble then how should I read these values out after they are stored in the database(some key value structure would be perfect).
You only need to form a xml with the content you want to show in your report:
<report>
<body>{$body}</body>
<inbound>{$inbound}</inbound>
...
</report>
the only requirement is that the output have to be an XML no matter the structure.
Not sure, but I would try something like this:
<myroot>{$body, $inbound, $outbound}</myroot>
Or if you really need a string returned:
fn:serialize(<myroot>{$body, $inbound, $outbound}</myroot>)
Note, fn:serialize is only in OSB 12c+.
I don't know if this has already been discussed here, but i have a question.
Is is possible in Thymeleaf to print the Variable name instead of null if it's not there.
For example, in Velocity if i have ${variable1} and i dont set the variable1, it just prints ${variable1}
Thanks
You can do it by Extending Thymeleaf features. I suppose you are thinking of this because of debug reasons, so simply do this:
<p th:text="${var}">var</p>
If the variable does not exist, the text inside is printed.
I am documenting my code using Shinx. In some files I have mathematical formulas and would like to include a reference to them. Being in the very same file this is not a problem. Using :eq:'reference'.
However, how do you cross reference to a formula from a different file? In my case Sphinx is unable to find the reference.
According to the Sphinx docs here, equation cross-referencing only works within the same document at present. I suggest submitting a bug/feature request to get this changed (assuming there isn't one already).
As a workaround, you can probably use the generic cross referencing syntax by placing a reference label immediately before the equation you want to reference (in the "other" file), like so:
.. _equation_in_other_file:
and then use something like:
:ref:` Link Title <equation_in_other_file>`
in the "current" file to reference it.
(note you need to provide an explicit link title)
It's not quite as elegant, but it should get the job done.
I'm reading in an XML file using XQuery and want to insert several nodes/elements and generate a new XML file. How can I accomplish this?
I've tried using the replace() function, but, it looks like all my XML tags are being stripped when I call doc() to load my document. So calling replace() isn't any good if my XML tags are being removed.
Any help? Are there other technologies I can use?
An extension to the XQuery language allowing updates -- the XQuery Update Facility -- exists to allow documents to be modified.
Inserting a node looks like this:
insert node <foo>bar</foo>
into /bar//baz[id='qux']
Among other engines, this is supported by BaseX.
See http://www.w3.org/TR/xquery-update-10/
replace() is a string operation, so the XML will be converted to a string before replacement.
To create a modified copy of the original file, you can modify an identity transformation which recursively copies the original file to insert the new nodes where required - see the article in the XQuery Wikibook
Alternatively if the file is in an XML database such as eXist, you can use update operations to insert elements in situ.
Using XQuery Scripting you can write programs like this:
variable $stores := doc("stores.xml")/stores;
insert node element store {
element store-number { 4 },
element state { "CA" }
} into $stores;
$stores
You can try such example live at http://www.zorba-xquery.com/html/demo#vpshT+pVURyQSCEOKrFBrF0jyGY=
I want to add an attribute to the dataset declared below whose value is the value of one of the field in the row.
So I want to add the id as shown below.
<root>
<Table id="GAS-405">
<apple>2009FA</apple>
<orange>3.00</orange>
<pear>BGPR</pear>
<banana>GAS-405</banana>
</Table>
</root>
This will help me identify the node later in my application.
Is this possible? Is this easier to do using XMLDocument?
Dim sdaFoo As SqlDataAdapter = New SqlDataAdapter("SELECT BLAH FROM BLAHBLAH", conn)
Dim dsFoo As DataSet = New DataSet()
dsFoo.DataSetName = "apple"
sdaFoo.Fill(dsFoo)
dsFoo.WriteXml("C:\Inetpub\wwwroot\foo.xml")
Dataset.WriteXml() is really a convenience method rather than a flexible way of dealing with XML.
You'll need to take another approach. There are a few options:
If you're just adding a single attribute, you could hack it into the resulting xml by re-opening the file as an XDocument, adding the attribute to the necessary element, and saving it again. Not too elegant, but easy, and sometimes easy is best. Even better, just use WriteXml() to put your xml into a string, then load the string as your XDocument.
Generate the XML from your query directly, rather than as a dataset. Sql Server 2005 and 2008 have some good XML methods that allow you to select a set of rows as XML (SELECT ... FOR XML) and specify what it looks like.
Use XmlSerialization for your dataset and inject the attribute using custom control of the serialization process.... which will be way more trouble than it's worth.
Store the attribute somewhere else outside of your XML and use some kind of object to keep track of it. Not really sure what your code is like, but that might be a great option.
Use GetXML() method of DataSet to get whole XML as a string. Then add your custom attributes and write that string into xml file using StreamWriter.