XSD validation optional string and only 4 numbers - xsd

I need a validation in this XSD.
FD is optional.
If you fill in FD it should have only 4 numbers (not 2 numbers or 5 numbers)
<xs:element name="FD" minOccurs="0" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>FD-code optional only 4 numbers</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="4" fixed="true"/>
<xs:pattern value="[0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Currently, the xsd rejects an empty value.
Question:
How do I get it to accept an empty value and if it does contain something filled that it only contains four digits?
So:
Empty is good
1 digit is wrong
2 digits is Wrong
3 digits is wrong
4 digits is Correct
5 digits is wrong
letters is wrong

The problem is probably that you are using length instead of maxLength. Also, the pattern that you use requires 4 numbers, not 0-4 numbers.
Try this instead:
<xs:element name="FD" minOccurs="0" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>FD-code optional only 4 numbers</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="4"/>
<xs:pattern value="([0-9]{4})?"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

Related

XSLT 1.0 - Selecting specific value from node string

I have this XML structure.
<Organisation>
<Employee type="gorilla">
<Publication>
The Hills and the Sunrise, 1-2013-05, $94,000
</Publication>
<Publication>
Sunny and Rainy on the same day, 1-2013-05, $584,932
</Publication>
</Employee>
<Employee type="gorilla">
<Publication>
The Hills and the Sunrise, 1-2013-05, $94,000
</Publication>
<Publication>
Sunny and Rainy on the same day, 1-2013-05, $584,932
</Publication>
</Employee>
<Employee type="pig">
<pigpen>
</pigpen>
</Employee>
</Organisation>
I would like to know how I can select only the dollar amount at the end of every Publication where an employe type = gorilla, and add these values together to give the total publication income. I would also like to use this total to calculate the average income per gorilla employee.
How could I go about doing this? I'm having trouble finding a function to select just the dollar amounts.
If there isn't a method to do this in XSLT 1, would it be considered good coding form to add more nodes to store the dollar amounts separately?
e.g.
<Publication>
<Description>The Hills and the Sunrise</Description>
<Amount>$94,000</Amount>
</Publication>

Changing date format with xslt string functions

I have to solve something with XSLT and am at a loss. I think I need the string-length function, some chose tests, and substring, but I don’t know. The problem is relatively simple.
My xml looks like the sample below. However, I have used YYYY, MM, and DD to represent numbers in the dates.
<date normal=”YYYMMDD”> Month, DD, YYYY</date>
<date normal=”YYYY/YYYY”> YYYY-YYYY</date>
<date normal=”YYYYMM”> Month, YYYY</date>
<date normal=”YYYYMM>MM-YYYY</date>
<name normal=”Smith, John”> John Smith </name>
I need to print all the elements as they are, except for JUST the two elements that have attributes normal=”YYYYMM”. They need to be printed but with attributes in the form normal=YYYY-MM
I cannot rely on the material in the element as it tends to be in a variety of different formats as it is free text.
I keep trying to use string-length function to identify attribute values with 6 characters in the element date. But then I can’t figure out how to split the string in the output with the hyphen. I am guessing it uses one of the substring functions, but I can’t get everything to work together.
Thanks for any advice you can give,
Christine
Something like this?:
<xsl:choose>
<xsl:when text="string-length(#normal) = 6 and number(#normal) = number(#normal)">
<xsl:value-of select="concat(substring(#normal, 1, 4), '-', substring(#normal, 5, 2))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#normal" />
</xsl:otherwise>
</xsl:choose>
The number(#normal) = number(#normal) check ensures that #normal is a number, since it looks like you also have some non-date values in the normal attribute. Is there any risk that it might be a 6-digit non-date number?
This complete and short transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="#normal[string-length()=6]">
<xsl:attribute name="normal">
<xsl:value-of select="concat(substring(.,1,4),'-',substring(.,5))"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
when applied on the following XML document (the provided fragment wrapped into a single top element):
<t>
<date normal="YYYMMDD"> Month, DD, YYYY</date>
<date normal="YYYY/YYYY"> YYYY-YYYY</date>
<date normal="YYYYMM"> Month, YYYY</date>
<date normal="YYYYMM">MM-YYYY</date>
<name normal="Smith, John"> John Smith </name>
</t>
produces the wanted, correct result:
<t>
<date normal="YYYMMDD"> Month, DD, YYYY</date>
<date normal="YYYY/YYYY"> YYYY-YYYY</date>
<date normal="YYYY-MM"> Month, YYYY</date>
<date normal="YYYY-MM">MM-YYYY</date>
<name normal="Smith, John"> John Smith </name>
</t>

iReport (JasperReports) extra row issue

I am getting an extra empty row between data when I am importing it from the database and formatting the report in Excel sheet.
EDIT (clarification from a comment): The output in Excel shows an extra blank row between records and and extra blank column between fields.
Add net.sf.jasperreports.export.xls.remove.empty.space.between.columns and net.sf.jasperreports.export.xls.remove.empty.space.between.rows properties to report template.
net.sf.jasperreports.export.xls.remove.empty.space.between.columns - Specifies whether the empty spacer columns should be removed or not.
net.sf.jasperreports.export.xls.remove.empty.space.between.rows - Specifies whether the empty spacer rows should be removed or not.
The sample:
<jasperReport ...>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
The information about configuration properties is here.
You can set isRemoveLineWhenBlank and isBlankWhenNull for textField element for hiding blank row.
The sample how to remove the whole line if the current textField is empty:
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="20" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
Another assumption is to change the height of all textField (or/and staticText) elements in the Band.
In case this design:
you will have a space between any two rows.
In case this design (textField height is equal to the Band's height):
the each line will be exactly under the other.
Every thing that Alex K states in his Dec 2 '11 answer is correct. But a few other settings may be helpful. These settings help when the text of the report stretches the detail band.
On every field in the detail band set:
positionType="Float"
stretchType="RelativeToTallestObject"
Example:
<detail>
<band height="20" splitType="Prevent">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Transparent" x="372" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{your column name}]]></textFieldExpression>
</textField>
This will force the all fields to be one height. The float setting tells the field to minimize the distance between the previous and next row. The RelativeToTallestObject setting tells all fields in the band to be the same height as the tallest field. These two settings help eliminate 'empty space' which shows up as unwanted cells in Excel.

maxIntegerDigits of jsf convertNumber

I've got strange problem with <f:convertNumber>. When i set maxIntegerDigits to 15 and enter, say, 16 of "1"s, i get correct number with fifteen "1"s, but if i enter 20 of "1"s i get not a number with fifteen "1"s but a number with 11 "1"s and 4 "0"s, i.e. 111111111110000, and the more digits i enter the less significant numbers and the more zeros i get. Why?
Here's code snippet:
<a4j:region>
<h:inputText id="numValue" value="#{MyBean.valueN}">
<a4j:support event="onchange" limitToList="true" ajaxSingle="true" reRender="numValue"/>
<f:convertNumber groupingUsed="false" type="number" maxIntegerDigits="15" minFractionDigits="0"/>
</h:inputText>
</a4j:region>
MyBean.valueN is java.lang.Double.
That's the nature of IEEE 754 floating point numbers. The largest value a double can hold is 1.7976931348623157e308 with that integer precision. Anything beyond this integer precision will be rounded.
You want to use the java.math.BigDecimal instead. This way your <f:convertNumber> will work as intented.

XSLT sorting:both ascending and descending

i have a sharepoint list column which has number datatype ..whenever the user sorts them ascending or descending i should get it as they were..but xslt sorting allows either ascending or descending..how can i make it flexible?..could anyone please help me with this
you can use conditional formating
<xsl:choose>
<xsl:when test="$sortorder='Asc'>
<xsl:call-template name="asctemplate" />
</xsl:when>
<xsl:when test="$sortorder='Desc'>
<xsl:call-template name="desctemplate" />
</xsl:when>
</xsl:choose>

Resources