Salesforce XSLT AccountContactRole ==> AccountContactRelations - xslt

Pretty new to XSLT... trying to convert an existing one based on SF Classic's "AccountContactRole" table to the newer "AccountContactRelations".. here's the snippit of the original I'm trying to convert to use the new "AccountContactRelations" table :
` <xsl:template match="*:AccountContactRole">
<row>
<SUBMITTER></SUBMITTER>
<SORT_ORDER>
<xsl:choose>
<xsl:when test="*:role='Billing Contact'">1</xsl:when>
<xsl:when test="*:role='Order Contact'">2</xsl:when>
<xsl:otherwise>3</xsl:otherwise>
</xsl:choose>
</SORT_ORDER>
<ROLE><xsl:value-of select="*:Role" /></ROLE>
</row>
</xsl:template>`
Of course, now the contacts are compressed to a single entry.. e.g., "Billing Contact;Order Contact;Sandwich Contact;SomeOther Contact" .. and.. they could be in any order, so I will need to iterate over this string until it is empty?
Thanks for any ideas / suggestions... perhaps someone has struggled with the same requirement before when migrating to AccountContactRelations?
~Pete

Related

How to append string values inside if condition

I am new to XSL.I have an XML as below, If CoverageCode equals -'HomeCoverage' then I have to verify for the next 3 elements of 'roofRestrictionEndt','sidingRestrictionEndt'and 'paintRestrictionEndt' . If 'roofRestrictionEndt' exits and its value is 'Y' then I need to print 'Roof' under the 'results' tag, If 'sidingRestrictionEndt' exists and its value is 'Y' then I need to print 'siding' in case if it exists along with the above one then I need to print 'Roof; siding'. If 'paintRestrictionEndt' exists and its value is 'Y' along with the other 2 elements then I need to print 'Roof; siding; paint'. I tried by declaring variables and wrote If conditions and tried to append values accordingly inside IF condition, but I came to know the declared variables are immutable. In java, we can achieve this by using StringBuffer. Is there any way to achieve this in XSL? Below is XML.
<locationCoverage ID="3">
<coverageCode >HomeCoverage</coverageCode>
<roofRestrictionEndt >Y</roofRestrictionEndt>
<sidingRestrictionEndt>Y</sidingRestrictionEndt>
<paintRestrictionEndt >Y</paintRestrictionEndt>
<locationCoverage>
Results should look like as below
<results>
<result>Roof;siding;paint</result>
</results>
If I have below input XML
<locationCoverage ID="3">
<coverageCode >HomeCoverage</coverageCode>
<roofRestrictionEndt >Y</roofRestrictionEndt>
<paintRestrictionEndt >Y</paintRestrictionEndt>
</locationCoverage>
For the above XML results should look like as below
<results>
<result>Roof;paint</result>
</results>
Appreciate it If anyone helps me with this. Thanks in advance.
If I understand this correctly (which is not at all certain), you want to do something like:
<xsl:template match="locationCoverage[coverageCode='HomeCoverage']">
<xsl:variable name="test-results">
<xsl:if test="roofRestrictionEndt='Y'">Roof </xsl:if>
<xsl:if test="sidingRestrictionEndt='Y'">siding </xsl:if>
<xsl:if test="paintRestrictionEndt='Y'">paint</xsl:if>
</xsl:variable>
<result>
<xsl:value-of select="translate(normalize-space($test-results), ' ', ';')"/>
</result>
</xsl:template>

Filter and sort table based XML

I am new to xslt and have done some research and read a brief book and looked at many examples but I'm afraid I just don't get it. I've only done simple procedural coding before and I guess I'm missing something. I understand a very basic example but when I try to transform my own data I am completely lost. Boo hoo hoo. It is soooo frustrating knowing that I don't it! I really feel like a hack :(
Anyway, I generated the following XML from a table in MS Word. The table ID and Row and Column IDs of each cell are given so it is possible to know how things relate to each other.
Now I want to present the data in a pick list and basically want to:
1. Filter the data on, say [Name='p_fld_parent_ref' and Value='RM12']. The data with the matching "rows" (i.e. all the nodes with the matching RowID) is what I want.
2. I also want to sort that filtered data on the column (cell) with name [p_fld_date_received]. I included a #dateSerial attribute specifically to make the sorting easier.
In the example data I should get any "rows" of data with a parent reference of 'RM12' sorted by date received. I want to use the data in the [p_fld_quantity_available] cell.
I've wasted about 3 days on this and gotten absolutely nowhere. Normally you start to get somewhere but with xslt I've gotten nowhere. Strange.
Here is one "row" of my data (sorry, I pasted the XML but don't know how to format it for reading - can someone let me know how to display it in the right format? Thanks.):
<Root><Data><Element><Name>p_fld_ref</Name><Key>SKU1</Key><KeyType>P</KeyType><ID>1</ID><Value>SKU1</Value><Description>Ref</Description><Required>True</Required><dataType>SKUn</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>1</ColumnID></Element><Element><Name>p_fld_parent_ref</Name><Key>SKU1</Key><KeyType>F</KeyType><ID>2</ID><Value>RM12</Value><Description>Parent Ref</Description><Required>True</Required><dataType>CPLn,RMn</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>2</ColumnID></Element><Element><Name>p_fld_item_no</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>3</ID><Value>ZRMH06</Value><Description>Item Code</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>3</ColumnID></Element><Element><Name>p_fld_type</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>4</ID><Value>RM</Value><Description>Type</Description><Required>True</Required><dataType>CA or RM</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>4</ColumnID></Element><Element><Name>p_fld_serial_no</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>5</ID><Value>120201</Value><Description>Serial No.</Description><Required>True</Required><dataType>Number</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>5</ColumnID></Element><Element><Name>p_fld_name_1</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>6</ID><Value>Product Name 1</Value><Description>Name 1</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>6</ColumnID></Element><Element><Name>p_fld_name_2</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>7</ID><Value>Product Name 1 Lang 2</Value><Description>Name 2</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>7</ColumnID></Element><Element><Name>p_fld_location</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>8</ID><Value/><Description>Location</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>8</ColumnID></Element><Element><Name>p_fld_receipt_no</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>9</ID><Value/><Description>Receipt No.</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>9</ColumnID></Element><Element><Name>p_fld_supplier</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>10</ID><Value/><Description>Supplier</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>10</ColumnID></Element><Element><Name>p_fld_supplier_ref</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>11</ID><Value/><Description>Supplier Ref</Description><Required>True</Required><dataType>Sn</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>11</ColumnID></Element><Element><Name>p_fld_supplier_batchno</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>12</ID><Value/><Description>Supplier Batch No.</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>12</ColumnID></Element><Element><Name>p_fld_supplier_coa</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>13</ID><Value/><Description>CoA Number</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>13</ColumnID></Element><Element><Name>p_fld_box_sample</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>14</ID><Value/><Description>Box to sample</Description><Required>True</Required><dataType>Text</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>14</ColumnID></Element><Element><Name>p_fld_number_boxes</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>15</ID><Value/><Description>Number of Containers</Description><Required>True</Required><dataType>Number</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>15</ColumnID></Element><Element><Name>p_fld_quantity_total</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>16</ID><Value/><Description>Total Quantity</Description><Required>True</Required><dataType>Number</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>16</ColumnID></Element><Element><Name>p_fld_date_received</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>17</ID><Value dateSerial="20130217000000">17-Feb-2013</Value><Description>Date Received</Description><Required>True</Required><dataType>Date</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>17</ColumnID></Element><Element><Name>p_fld_date_retest</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>18</ID><Value dateSerial="20140217000000">17-Feb-2014</Value><Description>Re-Test Date</Description><Required>True</Required><dataType>Date</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>18</ColumnID></Element><Element><Name>p_fld_date_expire</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>19</ID><Value dateSerial="20160217000000">17-Feb-2016</Value><Description>Expiry Date</Description><Required>True</Required><dataType>Date</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>19</ColumnID></Element><Element><Name>p_fld_date_released</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>20</ID><Value dateSerial="20130217000000">17-Feb-2013</Value><Description>Release Date</Description><Required>True</Required><dataType>Date</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>20</ColumnID></Element><Element><Name>p_fld_quantity_reserved</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>21</ID><Value>20000</Value><Description>Reserved Quantity</Description><Required>True</Required><dataType>Number</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>21</ColumnID></Element><Element><Name>p_fld_quantity_used</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>22</ID><Value>0</Value><Description>Used Quantity</Description><Required>True</Required><dataType>Number</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>22</ColumnID></Element><Element><Name>p_fld_quantity_available</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>23</ID><Value>20000</Value><Description>Available Quantity</Description><Required>True</Required><dataType>Number</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>23</ColumnID></Element><Element><Name>p_fld_status</Name><Key>SKU1</Key><KeyType>D</KeyType><ID>24</ID><Value/><Description>Status</Description><Required>True</Required><dataType>Q, R or X</dataType><parmType>1</parmType><TableID>6</TableID><RowID>3</RowID><ColumnID>24</ColumnID></Element></Root>
Assuming that each row is represented by a <Data> element (incidentally, you're missing the end tag of the <Data> element in this sample), this should do the filter/sorting part:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Root">
<Root>
<xsl:apply-templates
select="Data[Element[Name='p_fld_parent_ref']/Value='RM12']">
<xsl:sort select="Element[Name='p_fld_date_received]/Value/#dateSerial" />
</xsl:apply-templates>
</Root>
</xsl:template>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
You'll need to define a template for how you want your <Data> elements presented, and probably something other than simply re-creating the Root element as I've done above. Something as simple as this might do the trick, if you just want to output text:
<xsl:template match="Data">
<xsl:text>Item no.:</xsl:text>
<xsl:value-of select="Element[Name='p_fld_item_no']/Value" />
<xsl:text> Quantity available:</xsl:text>
<xsl:value-of select="Element[Name='p_fld_quantity_available']/Value" />
<xsl:text>
</xsl:text><!-- New line -->
</xsl:template>
This isn't a complete solution, but hopefully it'll give you enough pointers to figure out the rest.

Mapping a single element to a record using Scripting Functoid

I am trying to create a mapping between two different elements(Element1 & Element2) from source schema to the same record on Destination Schema along with an element in it as shown in the following format.
<coverages>
//If Element1(Source Schema element) has data
<coverage>
<CoverageTypeCd>Data1</CoverageTypeCd>
</coverage>
//If Element2(Source Schema element) has data
<coverage>
<CoverageTypeCd>Data2</CoverageTypeCd>
</coverage>
</coverages>
I am now trying to check the presence of value on Elements(Source Schema) and then trying to feed it to the scripting functoid. I don’t know how I should produce the entire
<coverage> node and still send the respective <coverageTypeCd> of that record as shown above. I believe it should be done with Inline XSLT. I really need someone’s help on this.
Thanks in advance.
Please let me know if you need additional details on something.
Update
Hi folks, I found the answer myself. I used Inline XSLT Call template as Script Type and it did the job. I applied this script for different elements on Source Schema to map the Coverage record
<xsl:template name="CoverageTemplate1">
<xsl:param name="Element1" />
<xsl:element name="Coverage">
<xsl:element name="CoverageTypeCd">
<xsl:value-of select="$Element1" />
</xsl:element>
</xsl:element>
</xsl:template>
Thanks
I found the answer myself. I used "Inline XSLT Call template" as Script Type and it did the job. I applied this script for different elements on Source Schema to map the Coverage record
<xsl:template name="CoverageTemplate1">
<xsl:param name="Element1" />
<xsl:element name="Coverage">
<xsl:element name="CoverageTypeCd"><xsl:value-of
select="$Element1" /></xsl:element>
</xsl:element>
</xsl:template>
Thanks

How Can I Reduce "When" Statement in XSLT

Hello I am writing a XSLT statement where I need to implement 1500 conditional statements like -
<xsl:when test="ID = '51'">
<br>
<xsl:text>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
<br>
<xsl:when test="ID = '52'">
<br>
<xsl:text>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
If i write statement like this way then my pages will be very slow. How can i reduce my code and write this statement in a smart way?
<xsl:variable name="idlist">
<ids>
<id>50</id>
<id>59</id>
<id>66</id>
...
</ids>
</xsl:variable>
<xsl:key name="idk" match="id" use="."/>
<xsl:when test="key('idk', ID, $idlist)">...
This is XSLT 2.0 but can be adapted to work with 1.0.
I can't see all your cases, but if the pattern from your first two continues and you want that same 'rightcolumn_seniorliv.jpg' for IDs 51 thru 1551 then
<xsl: when test="ID>'50' and ID<'1552'">
it sounds like these ID cases are going well beyond logic and into the data realm. i obviously dont know anything about your app, but perhaps an ID to imagename mapping somewhere (probably database) would be in order. depending on what process generates the XML file (the first one, before XSLT transformation), you might want to just set the image name (or lack thereof) explicitly thru this mapping. then lose the when all together

iterating over parallel xml elements in xslt

<var>1</var>
<value>not null</value>
<var>2</var>
<value>00FFFFFFF555555000100673</value>
<var>3</var>
<value>9694r</value>
If it were a list of vars I can iterate like
<xsl:for-each select="var">
.. crap code
</xsl:for-each>
But I need to catch the value related to var whenever i catch the var ,and display it in a table. I guess this is bad design , but I'm knee deep.
You could try using:
<xsl:value-of select="following-sibling::value"/>
in place of "crap code".
You can use the following-sibling axis:
<xsl:for-each select="var">
<xsl:value-of select="./following-sibling::value[1]" />
</xsl:for-each>