tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/4-attempting-to-reference-dynamic-metadataCascade CMS: Discussion 2018-10-18T20:35:59Ztag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-21T17:18:48Z2010-07-21T17:18:48ZAttempting to reference dynamic metadata<div><p>This is some untested code that, I believe, will work. I'm not
saying there isn't a better way to do it.</p>
<pre>
<code>#set ($systemFolder = $_XPathTool.selectNodes($contentRoot, "/system-folder"))
#foreach ($childElement in $systemFolder)
#if ($childElement.name == 'dynamic-metadata')
#if ($childElement.getChild('name').value == 'Time')
${childElement.getChild('value').value}
#end
#end
#end</code>
</pre></div>Eric L. Eppstag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-21T17:45:20Z2010-07-21T17:45:25ZAttempting to reference dynamic metadata<div><p>That appeared to fix the issue. I'll have to make more use of
XPath in the future. Thanks!</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-23T17:13:35Z2010-07-23T17:13:35ZAttempting to reference dynamic metadata<div><p>On second thought, that did not appear to work at all. I was
misreading some of the output. It returns absolutely nothing. Any
other ideas?</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-23T17:26:00Z2010-07-23T17:27:19ZAttempting to reference dynamic metadata<div><p>I generally do something like the following:</p>
<h1>set ($systemFolder = $_XPathTool.selectNodes($contentRoot,
"/system-folder"))</h1>
<h1>foreach ($folder in $systemFolder)</h1>
<pre>
<code>#set ($professorName = $_XPathTool.selectNode($folder, "dynamic-metadata[name='Professor Name']/value").value)
#set ($time = $_XPathTool.selectNode($folder, "dynamic-metadata[name='Time']/value").value)</code>
</pre>
<h1>end</h1></div>Pennytag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-23T19:32:59Z2010-07-23T19:32:59ZAttempting to reference dynamic metadata<div><p>Should this be able to run from the root of the XML document?
The folder with the dynamic values is three levels down. I'm still
getting no result.</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-23T20:10:25Z2010-07-23T20:10:25ZAttempting to reference dynamic metadata<div><p>If you copied my code exactly, you will need to output the
variables. I just stored the values. I would also change your
initial selctnodes to /system-index-block//system-folder rather
than just /system-folder of your element may be at various depths.
I hope this helps!</p></div>Pennytag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-26T18:27:51Z2010-07-26T19:14:57ZAttempting to reference dynamic metadata<div><p>I did the output, but still nothing. Here's what I have. I've
stripped it down to be ULTRA simple, but I'm still getting no
results of any sort. When I try to output the variables, I merely
get the variable names. Here's my script:</p>
<h1>macro (TestMacro)</h1>
<pre>
<code>#set ($systemFolder = $_XPathTool.selectNodes($contentRoot, "/system-index-block//system-folder"))
#foreach ($folder in $systemFolder)
#set ($professorName = $_XPathTool.selectNode($folder, "dynamic-metadata[name='Professor Name']/value").value)
#set ($time = $_XPathTool.selectNode($folder, "dynamic-metadata[name='Time']/value").value)
#end
$professorName <br />
$time <br /></code>
</pre>
<h1>end</h1>
<h1>TestMacro()</h1>
<p>And attached is a screenshot of the whole XML. I've tested the
loop, and that appears to be working. It's finding 5 nodes of type
"system-folder", which is correct. I'm just stuck beyond that.</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-27T21:09:42Z2010-07-27T21:09:42ZAttempting to reference dynamic metadata<div><p>If nothing else, will SOMEONE tell me where you can find some
documentation on XPathTool for use in velocity? Everything I've
looked up in XPath is not relating to velocity.</p>
<p>For example, this line of code:</p>
<h1>set ($divisions = $_XPathTool.selectNodes($contentRoot,
"/system-index-block/system-folder"))</h1>
<p>works exactly as one would expect. It selects all system folders
that are children of system-index-block. This returns three
elements that I can loop over. Each of those elements has a child
called "display-name". Trying to access this child through XPath
has been nigh on impossible. If I use the "getChild" command, that
works, but I'd like to be able to use XPath the entire time, for
consistency.</p>
<p>For example, this line:</p>
<h1>set ($nameVal = $division.getChild('display-name').value)</h1>
<p>works perfectly. I get the child node of the system-folder,
which is called "display-name". By tacking ".value" to the end of
it, I get the actual text of this node.</p>
<p>It would seem that this:</p>
<h1>set ($testVal = $_XPathTool.selectNodes($division,
"display-name").value)</h1>
<p>should work the same way. But it does not. Not even close.
Instead, when I try to output $testVal, I get the name of the
variable. Namely, "$testVal". Why is this the case? Should the
command above not select any nodes named "display-name" and give me
the value?</p>
<p>I thought perhaps I was not specifying the correct node, even
though there is only one at that level. Again, no dice. I changed
the code to the following line:</p>
<h1>set ($testVal = $_XPathTool.selectNodes($division,
"display-name[1]").value)</h1>
<p>Still nothing, still only outputting "$testVal". I tried using 0
as a position indicator as well. What am I doing wrong? And where
is the documentation on how to use $_XPathTool? It seems utterly
non-existent. What's most infuriating is that when I omit the
.value and output the variable, I get "[[Element: ]]". This would
imply that a node is actually being found. Why is it impossible to
get the value of that element? I've also tried replacing ".value"
with ".getValue()", and STILL nothing happens. What magic code am I
missing?</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-28T12:57:05Z2010-07-28T12:57:05ZAttempting to reference dynamic metadata<div><p>There is both $<em>XPathTool.selectNodes and
$</em>XPathTool.selectSingleNode. .selectNodes selects a group of
nodes you can loop through with a foreach, .selectSingleNode, well,
selects a single node. That may help with your above issues.</p>
<p>Also, the $contentRoot element is the full XML. Penny and I were
writing Velocity code based on what you provided, which was that
the root element was <system-folder>. In the second XML
example, we can see that your root element is
<system-index-block>. Try changing the first .selectNodes
selector to match your XML and see what happens.</p>
<p>As for documentation, here is Cascade's Velocity documentation:
<a href=
"http://www.hannonhill.com/kb/Script-Formats/">http://www.hannonhill.com/kb/Script-Formats/</a></p>
<p>Here is a link to the Velocity Webinar they did a couple months
ago:<br>
<a href=
"http://www.hannonhill.com/products/demos/velocity.html">http://www.hannonhill.com/products/demos/velocity.html</a></p>
<p>I also have found other sites' documentation on Velocity
scripting helpful, such as this one (if I can't find it in the HH
documentation, I go to Google): <a href=
"http://www.jajakarta.org/velocity/velocity-1.2/docs/api/org/apache/velocity/anakia/XPathTool.html">
http://www.jajakarta.org/velocity/velocity-1.2/docs/api/org/apache/...</a></p></div>Eric L. Eppstag:help-archives.hannonhill.com,2010-02-09:Comment/23263292010-07-29T14:44:39Z2010-07-29T14:44:39ZAttempting to reference dynamic metadata<div><p>That did it. Thanks.</p></div>webadmin