Output first string, not all children's strings - xslt

I'm having an issue with a bit XSLT code I'm working with for a client. I cannot change the schema, as a flash application depends on it and making any changes would break the ActionScript. It's unfortunate.
This is my first foray into XSLT and I'm admittedly incompetant with it, so I was hoping the community could help me out.
This is the schema (XML file):
<statement title="Click on your Answer" answer="true">
True or False: The question asked is here.
<feedback>
<answerTrue sound="">
The response if the user answered true is here.
</answerTrue>
<answerFalse sound="">
The response if the user answered false is here
</answerFalse>
</feedback>
</statement>
When I try to access the "statement" like this (XSLT):
<div id="statement">
<xsl:value-of select="statement" />
</div>
It displays the "answerTrue" and "answerFalse" nodes along with it. I would like to only display the text "True or False: The ques...". If anyone knows of a tag I can use to display the statement without displaying the child elements, I'd be eternally grateful! Thanks!

Use:
normalize-space(/statement/text()[1])

Related

Primeng KeyFilter not working well

i am using KeyFilter Module of primeng here is my code :
<input type="text" pInputText [(ngModel)]="price.TintCost" [pKeyFilter]="patternDecimal" name="tintCost" required="true" />
here is my typescrip code :
patternDecimal: RegExp = /^[0-9]+(\.[0-9]{1,2})?$/;
and here is version of primeng :|
"primeng": "^5.2.0-rc.1",
i tested in regex then i can type dot(.) but when i apply to KeyFilter, it doesn't allow the dot(.). Someone help me, please
I solved this problem by adding a mask as default
KeyFilter.DEFAULT_MASKS['currencyRegex'] = /^-?(?:0|[1-9]\d{0,2}(?:,?\d{3})*)(?:\.\d+)?$/;
I solved this problem by change the pValidateOnly property to true.
The problem is that the KeyFilter check any press on keyboard and if the complete value is no the correct, then dont permit write, just if you copy and paste the value.
In the documentation say
Instead of blocking a single keypress, the alternative validation mode
which is enabled with pValidateOnly property validates the whole input
with a built-in Angular validator.
https://www.primefaces.org/primeng-6.1.6/#/keyfilter
Example that work for me.
Component.ts
public twoDecimal: RegExp = /^\s*-?(\d+(\.\d{1,2})?|\.\d{1,2})\s*$/
Component.html
<input name="decimalField"
#decimalField="ngModel"
[pKeyFilter]="twoDecimal"
[pValidateOnly]="true"
[(ngModel)]="item.decimalField"
type="text" pInputText>
<div *ngIf="!decimalField.valid" class="alert alert-danger">
<p>Incorrect format.</p>
</div>
The answer of #Norberto Quesada is correct.
Without pValidateOnly the regex will validate on every key stroke.
Let's say you want to enter the value "47.11":
You begin to enter "4" => this would be valid, no input blocked.
Same for "47"
As soon as you enter "47. => validation fails, input blocked.
I was thinking maybe it's possible to enter "4711" first and then the "." in between but for some reason this doesn't seem to work, too... Maybe this is a bug?
Anyways, you can take a look at this stackblitz example for better understanding.
I've also prepared an example of using ValidateOnly and in addition to that restrict the input to only numbers using keyDown event

Can't read the XML node elements in ColdFusion

I'm trying to read some values from the XML file which I created, but it gives me the following error:
coldfusion.runtime.UndefinedElementException: Element MYXML.UPLOAD is undefined in XMLDOC.
Here is my code
<cffile action="read" file="#expandPath("./config.xml")#" variable="configuration" />
<cfset xmldoc = XmlParse(configuration) />
<div class="row"><cfoutput>#xmldoc.myxml.upload-file.size#</cfoutput></div>
Here is my config.xml
<myxml>
<upload-file>
<size>15</size>
<accepted-format>pdf</accepted-format>
</upload-file>
</myxml>
Can someone help me to figure out what is the error?
When I am printing the entire variable as <div class="row"><cfoutput>#xmldoc#</cfoutput></div> it is showing the values as
15 pdf
The problem is the hyphen - contained in the <upload-file> name within your XML. If you are in control of the XML contents the easiest fix will be to not use hyphens in your field names. If you cannot control the XML contents then you will need to do more to get around this issue.
Ben Nadel has a pretty good blog article in the topic - Accessing XML Nodes Having Names That Contain Dashes In ColdFusion
From that article:
To get ColdFusion to see the dash as part of the node name, we have to "escape" it, for lack of a better term. To do so, we either have to use array notation and define the node name as a quoted string; or, we have to use xmlSearch() where we can deal directly with the underlying document object model.
He goes on to give examples. As he states in that article, you can either quote the node name to access the data. Like...
<div class="row">
<cfoutput>#xmldoc.myxml["upload-file"].size#</cfoutput>
</div>
Or you can use the xmlSearch() function to parse the data for you. Note that this will return an array of the data. Like...
<cfset xmlarray = xmlSearch(xmldoc,"/myxml/upload-file/")>
<div class="row">
<cfoutput>#xmlarray[1].size#</cfoutput>
</div>
Both of these examples will output 15.
I created a gist for you to see these examples as well.

How come the get tag won't display any text in pyAIML?

I am working on a chat bot, just to see how it goes. I am using the PyAIML module. I currently am trying to get the user's name, and be able to use it when asked to. however, when I run the program, it doesn't show the name, only the text surrounding it. pardon my poor explanation of my problem. let me show you some code.
<category>
<pattern>MY NAME IS *</pattern>
<template>ok <star/>, I will do my best to remember that <star/> is your name.</template>
<think><set name = "name"><star/></set></think>
</category>
<category>
<pattern>WHAT IS MY NAME</pattern>
<template>I like to call you <get name = "name"/>. should I change it?
</template>
</category>
when run, the output does not include the name. all it says is:
<--I like to call you . Should I change it?
Am I doing something wrong?
Ps.(please be graceful, I just started AIML today :))
I'm not sure what the "think" tag is for, but I think that the main problem is that you have placed the "set" tag outside of the "template" tag.
Try something like this:
<template>ok <set name = "name"><star/></set>, I will do my best to remember that <get name = "name"/> is your name.</template>

Magento Product_List_Crosssell

The Crosssells do not seem to be working on my Magento EE install, for the product view page.
Ive debugged the product list crosssells block, but seems to crash out somewhere on its way through the various code, whilst collecting the collection. Cant work out why (whitescreens when debug to a certain level...and item collection thus not being set. Hard to figure out. No exceptions being logged).
I have no errors on the install...and sure i should not need to edit any logic, as the functionality is provided by default.
Ive followed this example:
http://www.magentocommerce.com/boards/viewthread/51529/
My crossells show on the cart page, as they usually do...but i cant get them to display on my product view page.
Heres my bits of code:
Catalog.xml:
<block type="catalog/product_list_crosssell" name="product.info.crosssell" as="crosssell_products" template="catalog/product/list/crosssell.phtml"/>
product/list/crosssell.phtml:
if(count($this->getItems())): ?>
<div id="also_bought_productslist" class="inner">
<?php $i=0;
foreach ($this->getItems() as $product):
Anyone know what i may be missing. And has anyone added crossells to their product view page?
Just to clarify...THIS IS USING THE DEFAULT PRODUCT_LIST_CROSSELL block...and im NOT trying to utilise the checkout/cart/crossell code (i know this relies on cart functionality/data to work correctly. I did attempt this though, and still get no crossell items....but they DO show in the cart page.)
many thanks
Syntax within the catalog xml file. Namely, an AFTER="blahblah" declaration...and use of same block code twice
Old code:
<block type="catalog/product_list_crosssell" name="product.info.crosssell" as="crosssell_products" template="catalog/product/list/crosssell.phtml"/>
<block type="catalog/product_list_related" name="alsoboughttabs" after="forgettoaddproducts" template="pagetabs/alsobought_pagetabs.phtml" />
<block type="catalog/product_list_related" name="forgettoaddproducts" after="product.info" template="catalog/product/list/dontforgettoadd.phtml" />
New code:
<block type="catalog/product_list_crosssell" name="product.info.crosssell" as="crosssell_products" template="catalog/product/list/crosssell.phtml"/>
<block type="catalog/product_list_upsell" name="alsoboughttabs" template="pagetabs/alsobought_pagetabs.phtml" />
<block type="catalog/product_list_related" name="forgettoaddproducts" after="product.info" template="catalog/product/list/dontforgettoadd.phtml" />

Returning child nodes of a particular type and their properties (Umbraco)

I'm trying to write some XSLT which basically should go through the following algorithm:
if child of current node is of type Accordion
if child of Accordion node is of type AccordionItem
take the AccordionItem's title and content and display in <div> tags
end if
end if
It seems pretty straight forward, but the code I currently have doesn't appear to be working as it should. I must be missing something, but I can't figure out exactly what. Here's my XSLT code so far:
<xsl:for-each select="$currentPage/ancestor-or-self::Home//AccordionItem[#isDoc]">
<div id="accordion">
<h3><a href='#'><xsl:value-of select="accordionItemTitle"/></a></h3>
<div><xsl:value-of select="accordionItemContent" disable-output-escaping="yes" />
</div>
</div>
</xsl:for-each>
Can anyone offer any suggestions as to why this wouldn't be working correctly? Thanks in advanced!
It seems that your XPath isn't quite behaving as you've defined in your algorithm and is navigating to the node of type Home, is that intended?
If not, try modifying the XPath to the following:
<xsl:for-each select="$currentPage/Accordion/AccordionItem[#isDoc]">