sbutt
-
Posts
22 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by sbutt
-
-
Hi All, I want to subtract '2 hours' from a given time in xslt 1. E.g.
<xsl:variable name="time"> <xsl:choose> <xsl:when test="ns0:DepartureTime !=''"> <xsl:value-of select="ns0:DepartureTime"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="'00:00:00'"/> </xsl:otherwise> </xsl:choose> </xsl:variable>
I want from this $time variable now subtract 2 hours and set it's value to an attribute.
<xsl:value-of select="$time"></xsl:value-of>
Could some please help?
-
Hi all, I am kind of stuck in implementing a rather tricky output for my given xml source. My input is:
<PickUpOpeningHours>08:00 - 22:00</PickUpOpeningHours>
And I want an output similar to:
<SubSection SubTitle="OfficeHours"><Paragraph Name="Monday"><Text>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOCCCCCCCC</Text></Paragraph><Paragraph Name="Tuesday"><Text>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOCCCCCCCC</Text></Paragraph><Paragraph Name="Wednesday"><Text>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOCCCCCCCC</Text></Paragraph><Paragraph Name="Thursday"><Text>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOCCCCCCCC</Text></Paragraph><Paragraph Name="Friday"><Text>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOCCCCCCCC</Text></Paragraph><Paragraph Name="Saturday"><Text>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOCCCCCCCC</Text></Paragraph><Paragraph Name="Sunday"><Text>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOCCCCCCCC</Text></Paragraph></SubSection>
Let me explain the output logic. C: closesO: opened Time is represented in 24 hours. 1 hour = 4 x 15 min (4 quarters)24 hours = 96 x 15 min (96 quarters) Total characters (C or O) will be 96 in total, where each character represents single quarter of time. The input xml could be of two different formats:
<PickUpOpeningHours>07:00 - 23:00</PickUpOpeningHours>
OR
<PickUpOpeningHours>08:30 - 12:00, 14:30 - 18:00</PickUpOpeningHours>
Can someone please help me out in devising some solution for the above problem using xslt 1? Thanks.
-
Hi All, I am kind of find it difficult to build my (xslt 1) template: I have this following XML input:
<Ticket> <ItineraryItem> <Flight ArrivalDateTime="2012-08-31T09:40:00" DepartureDateTime="2012-08-31T06:00:00" DirectionInd="Outbound"> <DepartureAirport LocationCode="BRN"/> <ArrivalAirport LocationCode="ZTH"/> <OperatingAirline Code="2L" FlightNumber="5320"/> </Flight> </ItineraryItem> <ItineraryItem> <Flight ArrivalDateTime="2012-09-14T11:00:00" DepartureDateTime="2012-09-14T10:15:00" DirectionInd="Inbound"> <DepartureAirport LocationCode="ZTH"/> <ArrivalAirport LocationCode="CFU"/> <OperatingAirline Code="2L" FlightNumber="5321"/> </Flight> </ItineraryItem> <ItineraryItem> <Flight ArrivalDateTime="2012-09-14T12:40:00" DepartureDateTime="2012-09-14T11:40:00" DirectionInd="Inbound"> <DepartureAirport LocationCode="CFU"/> <ArrivalAirport LocationCode="BRN"/> <OperatingAirline Code="2L" FlightNumber="5321"/> </Flight> </ItineraryItem> </Ticket>
And Have built the following template (xslt 1):
<xsl:template match="ota:Flight"><xsl:variable name="direction" select="@DirectionInd"/><Fat ServiceType="T"><xsl:attribute name="SegRef"><xsl:if test="java:setIndex($rph_pos, java:getIndex($rph_pos) + 1)"/><xsl:value-of select="format-number(java:getIndex($rph_pos) - 1,'000.#')"/></xsl:attribute><xsl:if test="../@Key"><xsl:attribute name="Key"><xsl:choose><xsl:when test="ota:CabinAvailability/ota:Seat/@Code"><xsl:variable name="code" select="ota:CabinAvailability/ota:Seat/@Code"/><xsl:value-of select="concat(substring(../@Key, 1, 10), $code, substring(../@Key, 12))"/></xsl:when><xsl:otherwise><xsl:value-of select="../@Key"/></xsl:otherwise></xsl:choose></xsl:attribute></xsl:if><StartDate><xsl:value-of select="datetime:format-date(substring(@DepartureDateTime, 1, 10), 'ddMMyyyy')"/></StartDate><Dep><xsl:value-of select="ota:DepartureAirport/@LocationCode"/></Dep><Arr><xsl:value-of select="ota:ArrivalAirport/@LocationCode"/></Arr><Persons><xsl:value-of select="translate(ota:CabinAvailability/ota:PassengerRPHs/@ListOfPassengerRPH,' ', '')"/></Persons></Fat>
And it generates the following output:
<Request><Fat ServiceType="T" SegRef="000"><StartDate>31082012</StartDate><Dep>BRN</Dep><Arr>ZTH</Arr><Persons>12</Persons></Fat><Fat ServiceType="T" SegRef="001"><StartDate>14092012</StartDate><Dep>ZTH</Dep><Arr>CFU</Arr><Persons>12</Persons></Fat><Fat ServiceType="T" SegRef="002"><StartDate>14092012</StartDate><Dep>CFU</Dep><Arr>BRN</Arr><Persons>12</Persons></Fat></Request>
Whereas I want an output to be like this:
<Request><Fat ServiceType="T" SegRef="000"><StartDate>31082012</StartDate><Dep>BRN</Dep><Arr>ZTH</Arr><Persons>12</Persons></Fat><Fat ServiceType="T" SegRef="001"><StartDate>14092012</StartDate><Dep>ZTH</Dep><Arr>BRN</Arr><Persons>12</Persons></Fat></Request>
That is to skip the intermediate flight, but only the start and end airports. In this above case, The outbound flight is fine, but there are 2 Inbound flights. I just want the starting Inbound airport and the final Inbound airport in the return flight. Similarly, there could be a scenario, where I have 2 Outbound flight, in that case the scenario woulc be the same that is the first Outboud flight and last Outboud flight. Normal scenario with single Outbound and Inbound flight are only covered at the moment by my template above. That case should stay as it is in the revised template. Your help in this regard should be highlly appreciated. Thanks.
-
Hi Folks, I am looking for a solution as to how I can mask some data that is part of a CDATA element. My currently implemented xslt-1 script works fine when my xml element/attribute is not placed inside cdata, for example, in the following xml snippet, I masked <CreditCardNumber> element's data: Input XML:
<?xml version="1.0" encoding="UTF-8"?><fareRequest da="true"><vcrs> <vcr>U2</vcr></vcrs><fareTypes/><tourOps/><flights> <flight depApt="SXF" depDate="2012-04-19" dstApt="BUD"/> <flight depApt="BUD" depDate="2012-04-25" dstApt="SXF"/></flights><CreditCardNumber>123456123</CreditCardNumber><limit>20</limit><offset>0</offset><waitOnList> <waitOn>ALL</waitOn></waitOnList><coses/></fareRequest>
XSLT-1 Script:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ota="http://www.opentravel.org/OTA/2003/05" xmlns:anyway="http://anyway.com/webservices/" xmlns:k="http://webservices.kuoni.ch" xmlns:xft="http://www.exchangefortravel.org/xft/current" xmlns:tu="http://tempuri.org/" xmlns:jet2="http://Jet2.Com/External/2009/01/V4"><xsl:output encoding="UTF-8" version="1.0" method="xml" indent="yes" cdata-section-elements="anyway:request k:request k:ForwardRequestResult xft:NameText xft:Description xft:URL xft:From xft:To xft:Code tu:XRq tu:ProcessTransactionXFTUResult libelle nom prenom adresse1 ville pays email"/><xsl:strip-space elements="*"/><!--add coma separated element names without namespace prefix to be masked, dont remove first coma! --><xsl:param name="names">!,Number,CCV,cc_number,cc_cvv,AccountNumber,CardSecurityCode,card_number,options,CreditCardNumber,CardNumber,IssueNumber,SecurityCode,</xsl:param><xsl:template match="/"> <xsl:apply-templates select="node()"/></xsl:template><xsl:template match="@*"> <xsl:variable name="attr-name" select="concat(',' , local-name() , ',')"/> <xsl:attribute name="{name()}" namespace="{namespace-uri()}"> <xsl:choose> <xsl:when test="string-length(substring-before($names, $attr-name)) > 0"> <xsl:call-template name="mask"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:attribute></xsl:template><xsl:template match="text()"> <xsl:copy/></xsl:template><xsl:template match="*"> <xsl:variable name="el-name" select="concat(',' , local-name(), ',')"/> <xsl:choose> <xsl:when test="string-length(substring-before($names, $el-name)) > 0"> <xsl:element name="{name()}" namespace="{namespace-uri()}"> <xsl:call-template name="mask"/> </xsl:element> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="*"/> </xsl:when> <xsl:otherwise> <xsl:element name="{name()}" namespace="{namespace-uri()}"> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:element> </xsl:otherwise> </xsl:choose></xsl:template><xsl:template name="index-of"> <xsl:param name="param1"/> <xsl:param name="param2"/> <xsl:value-of select="string-length(substring-before(concat(' ' ,$param1), $param2))"/></xsl:template><xsl:template name="mask"> <xsl:variable name="length" select="string-length(.)"/> <xsl:choose> <xsl:when test="$length > 3"> <xsl:value-of select="concat ('************', substring(.,$length - 1, 2))"/> </xsl:when> <xsl:when test="$length > 1">***</xsl:when> <xsl:otherwise/> </xsl:choose></xsl:template></xsl:stylesheet>
Output XML:
<?xml version="1.0" encoding="UTF-8"?><fareRequest da="true"><vcrs> <vcr>U2</vcr></vcrs><fareTypes/><tourOps/><flights> <flight depApt="SXF" depDate="2012-04-19" dstApt="BUD"/> <flight depApt="BUD" depDate="2012-04-25" dstApt="SXF"/></flights><CreditCardNumber>************23</CreditCardNumber><limit>20</limit><offset>0</offset><waitOnList> <waitOn>ALL</waitOn></waitOnList><coses/></fareRequest>
In the above example <CreditCardNumber>************23</CreditCardNumber> is masked properly. But when in my XML, I have the following scenario:
<?xml version="1.0" encoding="UTF-8"?><fareRequest da="true"><vcrs> <vcr>U2</vcr></vcrs><fareTypes/><tourOps/><flights> <flight depApt="SXF" depDate="2012-04-19" dstApt="BUD"/> <flight depApt="BUD" depDate="2012-04-25" dstApt="SXF"/></flights><![CDATA[<CreditCardNumber>123456123</CreditCardNumber>]]><limit>20</limit><offset>0</offset><waitOnList> <waitOn>ALL</waitOn></waitOnList><coses/></fareRequest>
That is <CreditCardNumber> inside CDATA, the script does not mask the data. Or in other words, everything that is contained inside CDATA, is ignored because it is not considered as an element or attribute by the xslt processor. Could somebody help me out in fixing this problem? Please note that my script is in XSLT 1. Thanks.
XSD Validation Error
in Schema
Posted