I am trying to do what should be a simple rename of nodes but am having difficulty getting the result I would like. The goal is to rename ALL nodes named "ROW" to "record". The factbase prior to the rename attempt is below. We are currently using Webmaker 4.
The rename action in my controller is using the following parameters.
Target location : /mvc:eForm/mvc :D ata/KEY_REQUEST_KEYS//ROW
New name : record
The result is that only the first instance of KEY_REQUEST_KEYS/ROW is changed to KEY_REQUEST_KEYS/record. After trying many different approaches I am starting to wonder if there is a way to accomplish this in Webmaker.
Any ideas would be much appreciated.
Thanks
Chuck
[size=100]
-<KEY_REQUEST_KEYS xmlns="">
-<ROW>
<PROCID>7846</PROCID>
<LN>1</LN>
<REQUEST_TYPE>N</REQUEST_TYPE>
<LOCKBOX>N</LOCKBOX>
<KEY_TYPE>M</KEY_TYPE>
<BUILDING>005X</BUILDING>
<ROOM>00917</ROOM>
<KEY_CLASS>CHGKEY</KEY_CLASS>
<PIN_REQUIRED>N</PIN_REQUIRED>
<KEY_REQUEST_ACCESS_TIME> </KEY_REQUEST_ACCESS_TIME>
</ROW>
-<ROW>
<PROCID>7846</PROCID>
<LN>2</LN>
<REQUEST_TYPE>N</REQUEST_TYPE>
<LOCKBOX>N</LOCKBOX>
<KEY_TYPE>E</KEY_TYPE>
<BUILDING>ENOLOGY</BUILDING>
<ROOM>14</ROOM>
<PIN_REQUIRED>N</PIN_REQUIRED>
<EFFECTIVE_DATE>10-OCT-14</EFFECTIVE_DATE>
<EXPIRATION_DATE>12-OCT-14</EXPIRATION_DATE>
-<KEY_REQUEST_ACCESS_TIME>
-<KEY_REQUEST_ACCESS_TIME_ROW>
<PROCID>7846</PROCID>
<KEYLN>2</KEYLN>
<LN>1</LN>
<SUNDAY>N</SUNDAY>
<MONDAY>Y</MONDAY>
<TUESDAY>N</TUESDAY>
<WEDNESDAY>N</WEDNESDAY>
<THURSDAY>Y</THURSDAY>
<FRIDAY>N</FRIDAY>
<SATURDAY>N</SATURDAY>
<START_TIME>07:00 AM</START_TIME>
<END_TIME>04:00 PM</END_TIME>
</KEY_REQUEST_ACCESS_TIME_ROW>
</KEY_REQUEST_ACCESS_TIME>
</ROW>
</KEY_REQUEST_KEYS> [/size]
The rename action in my controller is using the following parameters.
Target location : /mvc:eForm/mvc :D ata/KEY_REQUEST_KEYS//ROW
New name : record
The result is that only the first instance of KEY_REQUEST_KEYS/ROW is changed to KEY_REQUEST_KEYS/record. After trying many different approaches I am starting to wonder if there is a way to accomplish this in Webmaker.
Any ideas would be much appreciated.
Thanks
Chuck
[size=100]
-<KEY_REQUEST_KEYS xmlns="">
-<ROW>
<PROCID>7846</PROCID>
<LN>1</LN>
<REQUEST_TYPE>N</REQUEST_TYPE>
<LOCKBOX>N</LOCKBOX>
<KEY_TYPE>M</KEY_TYPE>
<BUILDING>005X</BUILDING>
<ROOM>00917</ROOM>
<KEY_CLASS>CHGKEY</KEY_CLASS>
<PIN_REQUIRED>N</PIN_REQUIRED>
<KEY_REQUEST_ACCESS_TIME> </KEY_REQUEST_ACCESS_TIME>
</ROW>
-<ROW>
<PROCID>7846</PROCID>
<LN>2</LN>
<REQUEST_TYPE>N</REQUEST_TYPE>
<LOCKBOX>N</LOCKBOX>
<KEY_TYPE>E</KEY_TYPE>
<BUILDING>ENOLOGY</BUILDING>
<ROOM>14</ROOM>
<PIN_REQUIRED>N</PIN_REQUIRED>
<EFFECTIVE_DATE>10-OCT-14</EFFECTIVE_DATE>
<EXPIRATION_DATE>12-OCT-14</EXPIRATION_DATE>
-<KEY_REQUEST_ACCESS_TIME>
-<KEY_REQUEST_ACCESS_TIME_ROW>
<PROCID>7846</PROCID>
<KEYLN>2</KEYLN>
<LN>1</LN>
<SUNDAY>N</SUNDAY>
<MONDAY>Y</MONDAY>
<TUESDAY>N</TUESDAY>
<WEDNESDAY>N</WEDNESDAY>
<THURSDAY>Y</THURSDAY>
<FRIDAY>N</FRIDAY>
<SATURDAY>N</SATURDAY>
<START_TIME>07:00 AM</START_TIME>
<END_TIME>04:00 PM</END_TIME>
</KEY_REQUEST_ACCESS_TIME_ROW>
</KEY_REQUEST_ACCESS_TIME>
</ROW>
</KEY_REQUEST_KEYS> [/size]
RE: XPATH Controller Rename
You should be able to do this ok.
The important thing to remember is that the actions in each rule generally only apply to the first element in the XML that they match. In order to apply one or more actions to multiple elements you need to use a looping rule.
So in your case you would need to create a rule with a single condition whose Check XPath is '/mvc:eForm/mvc :D ata/KEY_REQUEST_KEYS//ROW'. Then make sure the LOOP icon is clicked to turn this on for the condition. This means that the set of actions in this rule will be processed for every element matched by the condition XPath (ie all of the ROW elements).
(As an aside, you may not need the double slash in your XPath if all the ROW elements are at the same level in the XML, as is the case with the data you've provided.)
Then add a single rename action to this rule. The only difference here due to the looping rule is that you should set the target location XPath for the rename to just '.'
In XPath the dot refers to the current context, and for a looping rule this will be automatically set to the correct element (from the set matched by the condition XPath) every time the rule actions are fired.
I hope this helps, and please let me know if you have any questions.
Regards,
Gerard
RE: XPATH Controller Rename
Thanks Gerard.
Using a loop works fine, but instead I ended up using an xsl stylesheet to do the transform. Thank you for pointing out that each rule only points to the first match in the XML structure. Now I understand why I was getting unexpected results. Below is a copy of the stylesheet I ended up using.
Thanks again for all your help.
Chuck
<xsl :s tylesheet version="1.0" xmlns="http://www.hyfinity.com/xstore" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="KEYXML/ROWSET">
<KEY_REQUEST_KEYS xmlns="">
<xsl:apply-templates select="@*|node()" />
</KEY_REQUEST_KEYS>
</xsl:template>
<xsl:template match="KEY_REQUEST_ACCESS_TIME_ROW">
<record xmlns="">
<xsl:apply-templates select="@*|node()" />
</record>
</xsl:template>
<xsl:template match="ROW">
<record xmlns="">
<xsl:apply-templates select="@*|node()" />
</record>
</xsl:template>
</xsl :s tylesheet>