XSLT title auto-generate - html

I'm fairly green when it comes to XML/XSLT email builds. I cannot figure out how to properly call the "CampaignName" and place it into the tag.
My XML is as such:
<KANARoot>
<EventRequest Id="" CompanyName="default" CampaignName="Statement_Notification">
<Customer KeyField="alt_customer_id" alt_customer_id="-1" EmailAddress="customer#gmail.com" First_Name="Customer" Last_Name="Name" Address_Line1="" Address_Line2="" City="" State="" Postal_Code="">
<CustomerAttribute Name="workOrder"/>
<CustomerAttribute Name="soaMessageId">10</CustomerAttribute>
<CustomerAttribute Name="accountType">R</CustomerAttribute>
<CustomerAttribute Name="accountEsbNamespace">8448200010063009</CustomerAttribute>
<CustomerAttribute Name="billingID">202</CustomerAttribute>
<CustomerAttribute Name="divisionId">CAR</CustomerAttribute>
<CustomerAttribute Name="workOrderTimestamp">2013-01-31T10:01:41.109-05:00</CustomerAttribute>
</Customer>
<Event CampaignName="Statement_Notification">
<ExternalXML>
<CustomerInfo>
<CustomerName>Customer Name</CustomerName>
<CustomerBusinessName>Customer</CustomerBusinessName>
<PaperLessFlag>Paperless</PaperLessFlag>
<CustomerEmailAddress>sandhya#gmai.com</CustomerEmailAddress>
</CustomerInfo>
<StatementInfo>
<AccountNumber>8448200000000001</AccountNumber>
<StatementCode/>
<StatementDate>01/31/2013</StatementDate>
<StatementDueDate>01/31/2013</StatementDueDate>
<StatementFromDate>01/31/2013</StatementFromDate>
<StatementToDate>01/31/2013</StatementToDate>
<AmountDue>1000.00</AmountDue>
</StatementInfo>
<DivisionInfo>
<DivisionID>CAR.202</DivisionID>
<BillingSystem>ACP</BillingSystem>
</DivisionInfo>
</ExternalXML>
</Event>
</EventRequest>
My XLST so far is:
<title><xsl:value-of select="EventRequest/Event/CampaignName" /></title>
But that isn't working. Thanks for any help.

CampaignName is an attribute, not a child element of the Event, so you need an XPath such as EventRequest/Event/#CampaignName

Related

How to create a custom system field in magento 1?

Magento 1.9
I want to create a new tab in System > Configuration.
In this tab, I need a group tab and in this group tab i want a textarea which is connected to a field of my database. If i edit my textarea, it will modify my database field too.
Look at this: https://prnt.sc/orwph1
I don't know how to connect my textarea with my db.. Create a new tab with a new group it's easy but connect it to the db..
Thanks!
let's assume you want a section that has 2 fields: multiselect, text area. In the multiselect you have all your customer and in the text are you get the modify to apply for a certain db field (related to the customer).
your system.xml should me something like this:
<config>
<tabs>
<admin_customTab_2 translate="label" module="sections">
<label>- TAB NAME -</label>
<sort_order>2</sort_order>
</admin_customTab_2>
</tabs>
<sections>
<customsection2 translate="label" module="sections">
<label>label name</label>
<tab>admin_customTab_2</tab>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<block translate="label">
<label>label name</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<block_customers>
<label>Select user</label>
<comment>user list</comment>
<frontend_type>multiselect</frontend_type>
<backend_model>sections/users</backend_model>
<source_model>sections/users</source_model> <!-- adding a source-model for the form's select -->
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</block_customers>
<block_textarea>
<label>changes to apply</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</block_textarea>
</fields>
</block>
</groups>
</customsection2>
</sections>
this is not enough for the configs, you need to tell Magento about the access control list (ACL) or admin-users will not see it. It is done in the config.xml
like this:
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<customsection2>
<title>Customer Changes?</title>
</customsection2>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
all is setted, but doing nothing but showing us the tabs and forms.
If you was brave enough you noticed a tag in the system.xml code up here,
<backend_model>sections/users</backend_model>
<source_model>sections/users</source_model> <!-- adding a source-model for the form's select -->
this tell magento that you are using a model relating to this form, where you can do operations.
So, in your Model's path create the (in this example) User.php
and here we go:
you want to extend your custom class with this one.
class Admin_Sections_Model_Users extends Mage_Core_Model_Config_Data
yes but we still didn't insert any data in the form.
You can do this by just adding a special function toOptionArray() :
public function toOptionArray()
{
$collections = Mage::getModel("customer/customer")->getCollection();
foreach ($collections as $colletion){
$user = Mage::getModel("customer/customer")->load($colletion->getId());
$array[] = array('value'=>$user->getEntityId(),'label'=>Mage::helper("sections")->__($user->getName()));
}
return $array ;
}
this will set ALL the customer's name into the multi-select form.
"yeah, nice.. I asked about the text-area"
before telling you how to get Data from Store Configs, you should know that there are 2 main methods for elaborating the form data:
public function _afterSave()
{}
public function _beforeSave()
{}
in there you can put all your code, no need to explain what is the difference between them.
in this function you can easy get the Data from Store Config by doing:
$text_area_string = Mage::getStoreConfig('customsection2/block/block_textarea');
"yeah nice... but my main problem is to save things in DB"
you can use whenever you prefer the Mage::getModel('') method , this can connect you to the database. Lets make an example; modify the 'is_active' field on 'customer_entity' table.
$customer = Mage::getModel("customer/customer")->load($customer_id);
$customer->setData("is_active",0);
$customer->save();
this field doesn't do really anything, it is just a very fast example.
This should let you do what you are aiming for.
If something sounds strange, please let me know!

SLD - place label on each multipoint

I have a multipoint geometry (a single geometry containing multiple points) and I want to place a label on each of the points (the label is always the same). Is it possible to achieve this with SLD? Right now the label is only displayed on a single point.
My SLD looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Multipoint with labels</Name>
<UserStyle>
<Title>Default Point</Title>
<Abstract>A sample style that draws a point</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>rule1</Name>
<Title>Red Square</Title>
<Abstract>A 6 pixel square with a red fill and no stroke</Abstract>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>square</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
<TextSymbolizer>
<Label>NAME</Label>
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
By default the GeoServer label engine goes to a lot of trouble to not label multiple times on the same feature, so this is hard!
I finally managed it using the following (ugly) SLD:
<Rule>
<Title>Capitals</Title>
<TextSymbolizer>
<Geometry>
<ogc:Function name="getGeometryN">
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:Function>
</Geometry>
<Label>ID</Label>
</TextSymbolizer>
<TextSymbolizer>
<Geometry>
<ogc:Function name="getGeometryN">
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:Function>
</Geometry>
<Label>ID</Label>
</TextSymbolizer>
<TextSymbolizer>
<Geometry>
<ogc:Function name="getGeometryN">
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Literal>2</ogc:Literal>
</ogc:Function>
</Geometry>
<Label>ID</Label>
</TextSymbolizer>
<TextSymbolizer>
<Geometry>
<ogc:Function name="getGeometryN">
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Literal>3</ogc:Literal>
</ogc:Function>
</Geometry>
<Label>ID</Label>
</TextSymbolizer>
</Rule>
However this assumes you know how many points there are in your largest multi-point, and that is quite small (otherwise it's a lot of copy & paste).
I had originally hoped to be able to use the vertices function or possibly the labelAllGroup vendor option, but sadly neither worked with multi-points.

Parsing html with xslt

Can someone help me take the following:
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>This is a test</title>
<link>http://somelink.html</link>
<description>RSS Feed</description>
<item>
<title>This is a title</title>
<link>http://somelink.html</link>
<description><div style='font-size: 9px;'><div class="rendering rendering_researchoutput rendering_researchoutput_short rendering_contributiontojournal rendering_short rendering_contributiontojournal_short"><h2 class="title"><a class="link" rel="ContributionToJournal" href="http://somelink.html"><span>This is a Title</span></a></h2><a class="link person" rel="Person" href="somelink.html"><span>Bob, C. R</span></a> &amp; Smith, W. <span class="date">2014</span> <span class="journal">In : <a class="link" rel="Journal" href="http://somelink.html"><span>Publishers title</span></a>.</span><p class="type"><span class="type_family">Research output<span class="type_family_sep">: </span></span><span class="type_classification_parent">Contribution to journal<span class="type_parent_sep"> › </span></span><span class="type_classification">Article</span></p></div><div class="rendering rendering_researchoutput rendering_researchoutput_detailsportal rendering_contributiontojournal rendering_detailsportal rendering_contributiontojournal_detailsportal"><div class="article"><table class="properties"><tbody><tr class="language"><th>Original language</th><td>English</td></tr><tr><th>Journal</th><td><a class="link" rel="Journal" href="http://somelink.html"><span>Journal of Human Rights and the Environment </span></a></td></tr><tr><th>Journal publication date</th><td>2014</td></tr><tr class="status"><th>State</th><td>In press</td></tr></tbody></table></div></div></div></description>
<pubDate>Wed, 02 Apr 2014 15:59:41 GMT</pubDate>
<guid>http://somelink.html</guid>
<dc:date>2014-04-02T15:59:41Z</dc:date>
</item>
</channel>
</rss>
And show me how to use XSLT to parse the <description> tag to return the contents of the <span class="..."> fields or <div class='...'> fields?
I tried the following in my xslt:
<xsl:value-of select="span[#class='date']"/>
Which returns nothing
Here's a clumsy way to extract the contents of the <span class="date"> element (or rather what would be the <span class="date"> element after disabling the escaping):
<xsl:value-of select="substring-before(substring-after(description, '<span class="date">'), '</span>')"/>

Select the first <img> tag after an <input> tag using xpath

I have HTML as given below :
<root>
<Customer cid= "C1" name="Janine" city="Issaquah">
<input name="Client.ClaimsAdjudicationPendReason" />
<a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudicationPendReason','','')>
<img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif"/>
<input name="Client.ClaimsAdjudication" />
<a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudication','','')>
<img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif"/>
</Customer>
</root>
Using the below xpath, I'm able to selected the 'input' node where
name="Client.ClaimsAdjudicationPendReason"
xpath:=//input[#name='Client.ClaimsAdjudicationPendReason']
But I need to select the img node (just below a tag) where
name="Client.ClaimsAdjudicationPendReason"
The original html had some bits missing, see my comment above. So assuming this is what was intended:
<root>
<Customer cid="C1" name="Janine" city="Issaquah">
<input name="Client.ClaimsAdjudicationPendReason" />
<a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudicationPendReason','','')" />
<img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif" />
<input name="Client.ClaimsAdjudication" />
<a onclick="javascript:pendReasonLookup('MFM_Pend Reason', 'PendReason','txtClaimsAdjudication','','')" />
<img title="Lookup" class="imgSearchIcon" alt="Lookup" src="/F005web/images/search.gif" />
</Customer>
</root>
The xpath below will select the first img node after input with name "Client.ClaimsAdjudicationPendReason"
//input[#name="Client.ClaimsAdjudicationPendReason"]/following-sibling::img[1]

Techniques for building HTML in code

An html template is compiled into the application as a resource. A fragment of the HTML template looks like:
<A href="%PANELLINK%" target="_blank">
<IMG border="0" src="%PANELIMAGE%" style="%IMAGESTYLE%">
</A><BR>
%CAPTIONTEXT%
i like it like this because the larger resource HTML file contains styling, no-quirks mode, etc.
But as is always the case, they now want the option that the Anchor tag should be omitted if there is no link. Also if there is no caption, then the BR tag should be omitted.
Considered Technique Nº1
Given that i don't want to have to build entire HTML fragments in C# code, i considered something like:
%ANCHORSTARTTAGPREFIX%<A href="%PANELLINK%" target="_blank">%ANCHORSTARTTAGPOSTFIX%
<IMG border="0" src="%PANELIMAGE%" style="%IMAGESTYLE%">
%ANCHORENDTAGPREFIX%</A>%ANCHORENDTAGPOSTFIX%CAPTIONPREFIX%<BR>
%CAPTIONTEXT%%CAPTIONPOSTFIX%
with the idea that i could use the pre and postfixes to turn the HTML code into:
<!--<A href="%PANELLINK%" target="_blank">-->
<IMG border="0" src="%PANELIMAGE%" style="%IMAGESTYLE%">
<!--</A>--><!--<BR>
%CAPTIONTEXT%-->
But that is just rediculous, plus one answerer reminds us that it wastes bandwith, and can be buggy.
Considered Technique Nº2
Wholesale replacement of tags:
%AnchorStartTag%
<IMG border="0" src="%PANELIMAGE%" style="%IMAGESTYLE%">
%AnchorEndTag%%CaptionStuff%
and doing a find-replace to change
%AnchorStartTag%
with
"<A href=\"foo\" target=\"blank\""
Considered Technique Nº3
i considered giving an ID to the important HTML elements:
<A id="anchor" href="%PANELLINK%" target="_blank">
<IMG border="0" src="%PANELIMAGE%" style="%IMAGESTYLE%">
</A><BR id="captionBreak">
%CAPTIONTEXT%
and then using an HTML DOM parser to programatically delete nodes. But there is no easy access to a trustworthy HTML DOM parser. If the HTML was instead xhtml i would use various built-in/nativly available xml DOM parsers.
Considered Technique Nº4
What i actually have so far is:
private const String htmlEmptyTemplate =
#"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01//EN\"""+Environment.NewLine+
#" ""http://www.w3.org/TR/html4/strict.dtd"">"+Environment.NewLine+
#"<HTML>"+Environment.NewLine+
#"<HEAD>"+Environment.NewLine+
#" <TITLE>New Document</TITLE>"+Environment.NewLine+
#" <META http-equiv=""X-UA-Compatible"" content=""IE=edge"">"""+Environment.NewLine+
#" <META http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"">"+Environment.NewLine+
#"</HEAD>"+Environment.NewLine+
#""+Environment.NewLine+
#"<BODY style=""margin: 0 auto"">"+Environment.NewLine+
#" <DIV style=""text-align:center;"">"+Environment.NewLine+
#" %ContentArea%"+Environment.NewLine+
#" </DIV>" + Environment.NewLine +
#"</BODY>" + Environment.NewLine +
#"</HTML>";
private const String htmlAnchorStartTag =
#"<A href=""%PANELLINK%"" target=""_blank"">";
//Image is forbidden from having end tag
private const String htmlImageTag =
#"<IMG border=""0"" src=""%PANELIMAGE%"" style=""%IMAGESTYLE%"">";
private const String htmlCaptionArea =
#"<BR>%CAPTIONTEXT%";
And i already want to gouge my eyeballs out. Building HTML in code is a nightmare. It's a nightmare to write, a nightmare to debug, and a nightmare to maintain - and it will makes things difficult on the next guy. i'm hoping for another solution - since i am the next guy.
My reputation points in this game already being low gives me the freedom to tell you quite plainly that you, sir or madame, are in serious need of XSLT. Failing this (and you probably will) you need to look at XML literals in VB.NET (which provides you with the template-based solution you are looking for...). Since I prefer to stay in C# (even though I was born and raised on VBA), I use XSLT.
Both of my unwelcome recommendations require the use of XHTML instead of HTML. This requirement alone is quite a turn off to many traditional developers. I can already see through your use of capital letters for HTML elements that you will find my remarks utterly useless. So I should stop writing now.
What about this: Store XML as your fragment:
<fragment type="link_img_caption">
<link href="%PANELLINK%" />
<img src="%PANELIMAGE%" style="%IMAGESTYLE%" />
<caption text="%CAPTIONTEXT%" />
</fragment>
Pull it out, replace the placeholders with the "real" strings (that you have carefully XML-escaped of course),
...and use a simple XML transformation to produce HTML output:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="fragment" />
</xsl:template>
<xsl:template match="fragment[#type = 'link_img_caption']">
<xsl:choose>
<xsl:when test="link[#href != '']">
<a href="{link/#href}" target="_blank">
<img src="{img/#src}" style="{img/#style}" border="0" />
</a>
</xsl:when>
<xsl:otherwise>
<img src="{img/#src}" style="{img/#style}" border="0" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="caption[#text !='']">
<br />
<xsl:value-of select="caption/#text" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Other fragment types could be added because of the type attribute. There is much room to improve this, so look at it as an example of how it could be done.
Output:
<a href="%PANELLINK%" target="_blank">
<img src="%PANELIMAGE%" style="%IMAGESTYLE%" border="0">
</a>
<br>
%CAPTIONTEXT%
and, if the link href is empty in the XML:
<img src="%PANELIMAGE%" style="%IMAGESTYLE%" border="0">
<br>
%CAPTIONTEXT%
Use a templating engine, like one of these.
1.) Don't use comments, you'll send useless data to the browser wasting bandwidth and encountering BUGs in IE.
2.) Would this not be better as some sort of method? (I'm not familiar with C#) but something like this makes more sense to me.
//using PHP in this example
function HTMLImage($imageData, $linkData){
var str = '';
//if there is link data, start <a> tag
$str .= '<a '.{expand any attributes}.'>';
//add image tag and attributes from $imageData
$str .= '<img '.{expand any attributes}.'/>';
//if there is link data, close <a> tag
$str .= '</a>';
return $str;
}
I would use Template Toolkit, unfortunately it is currently only implemented in Perl and Python.
test.pl:
use Template;
my $template = Template->new({
VARIABLES => {
ImageStyle => "default",
CaptionText => "Place Caption Here"
},
});
$template->process( 'test.tt', {
panel => {
link => "http://Stackoverflow.com/",
image => "/Content/Img/stackoverflow-logo-250.png",
alt => "logo link to homepage"
}
} );
test.tt:
[% IF panel.link -%]
<A href="[% panel.link %]" alt="[% panel.alt %]" target="_blank">
[%- END -%]
[%- IF panel.image -%]
<IMG border="0" src="[% panel.image %]" style="[% ImageStyle %]">
[%- END -%]
[%- IF panel.link %]</A>[% END %]<BR>
[% CaptionText %]
Outputs:
<A href="http://Stackoverflow.com/" alt="logo link to homepage" target="_blank">
<IMG border="0" src="/Content/Img/stackoverflow-logo-250.png" style="default">
</A><BR>
Place Caption Here
If the variable panel.link isn't defined it skips the anchor tags.
<IMG border="0" src="/Content/Img/stackoverflow-logo-250.png" style="default">
<BR>
Place Caption Here
Templates are a serious code smell. Take a look at how Seaside generates html.
[Edit] Another one where someone without a clue downvoted.