Stylesheets not recognizing empty chapter - dita

DITA-OT: 1.7.3
Problem:
I get an error on an empty chapter in my custom stylesheets:
"fo:block-container" is missing child elements. Required content model: marker* (%block;)+
Default PDF2 styles render fine.
Adding a topic to the chapter makes it go away. The error only gives me the last line number of topic.fo with a column of 0.
Here is the page-sequence (indented), the line the error is on starts right before id="d2e394":
<fo:page-sequence
xmlns:xs="http://www.w3.org/2001/XMLSchema"
force-page-count="no-force"
initial-page-number="1"
master-reference="body-sequence">
<fo:static-content
flow-name="xsl-footnote-separator">
<fo:block>
<fo:leader
color="black"
leader-length="25%"
leader-pattern="rule"
rule-style="solid"
rule-thickness="0.5pt"/>
</fo:block>
</fo:static-content>
<fo:static-content
flow-name="odd-body-footer">
<fo:table
font-size="8pt"
space-after="0.5in"
space-after.conditionality="retain"
text-align="end"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:table-column
column-width="40%"/>
<fo:table-column
column-width="20%"/>
<fo:table-column
column-width="40%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block
margin-left=".93in"
text-align="left">PN: XXXXXX</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
text-align="center">
<fo:retrieve-marker
retrieve-class-name="current-chapter-number"/>-<fo:page-number/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
margin-right="0.74in"
text-align="right">
<fo:retrieve-marker
retrieve-class-name="current-document-header"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:static-content
flow-name="even-body-footer">
<fo:table
font-size="8pt"
space-after="0.5in"
space-after.conditionality="retain"
text-align="end"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:table-column
column-width="40%"/>
<fo:table-column
column-width="20%"/>
<fo:table-column
column-width="40%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block
margin-left=".93in"
text-align="left">PN: XXXXXX</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
text-align="center">
<fo:retrieve-marker
retrieve-class-name="current-chapter-number"/>-<fo:page-number/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
margin-right="0.74in"
text-align="right">
<fo:retrieve-marker
retrieve-class-name="current-document-header"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:static-content
flow-name="odd-body-header">
<fo:table
font-size="8pt"
margin-top="0.50in"
space-before="10pt"
space-before.conditionality="retain"
text-align="end"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:table-column
column-width="50%"/>
<fo:table-column
column-width="50%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell
display-align="after">
<fo:block
border-bottom="1pt solid black"
margin-left=".93in"
text-align="left">
<fo:retrieve-marker
retrieve-class-name="current-h2"/>
</fo:block>
</fo:table-cell>
<fo:table-cell
display-align="after">
<fo:block
border-bottom="1pt solid black"
margin-right="0.74in"
text-align="right">
<fo:retrieve-marker
retrieve-class-name="current-chapter-header"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:static-content
flow-name="even-body-header">
<fo:table
font-size="8pt"
margin-top="0.50in"
space-before="10pt"
space-before.conditionality="retain"
text-align="end"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:table-column
column-width="50%"/>
<fo:table-column
column-width="50%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell
display-align="after">
<fo:block
border-bottom="1pt solid black"
margin-left=".93in"
text-align="left">
<fo:retrieve-marker
retrieve-class-name="current-h2"/>
</fo:block>
</fo:table-cell>
<fo:table-cell
display-align="after">
<fo:block
border-bottom="1pt solid black"
margin-right="0.74in"
text-align="right">
<fo:retrieve-marker
retrieve-class-name="current-chapter-header"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:static-content
flow-name="first-body-header">
<fo:block
end-indent="10pt"
space-before="10pt"
space-before.conditionality="retain"
text-align="end"/>
</fo:static-content>
<fo:static-content
flow-name="first-body-footer">
<fo:table
font-size="8pt"
space-after="0.5in"
space-after.conditionality="retain"
text-align="end"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:table-column
column-width="40%"/>
<fo:table-column
column-width="20%"/>
<fo:table-column
column-width="40%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block
margin-left=".93in"
text-align="left">PN: XXXXXX</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
text-align="center">
<fo:retrieve-marker
retrieve-class-name="current-chapter-number"/>-<fo:page-number/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
margin-right="0.74in"
text-align="right">
<fo:retrieve-marker
retrieve-class-name="current-document-header"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:static-content
flow-name="last-body-header">
<fo:block/>
</fo:static-content>
<fo:static-content
flow-name="last-body-footer">
<fo:table
font-size="8pt"
space-after="0.5in"
space-after.conditionality="retain"
text-align="end"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:table-column
column-width="40%"/>
<fo:table-column
column-width="20%"/>
<fo:table-column
column-width="40%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block
margin-left=".93in"
text-align="left">PN: XXXXXX</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
text-align="center">
<fo:retrieve-marker
retrieve-class-name="current-chapter-number"/>-<fo:page-number/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block
margin-right="0.74in"
text-align="right">
<fo:retrieve-marker
retrieve-class-name="current-document-header"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:flow
flow-name="xsl-region-body">
<fo:marker
marker-class-name="current-topic-number">6</fo:marker>
<fo:marker
marker-class-name="current-chapter-header">test</fo:marker>
<fo:marker
marker-class-name="current-document-header">
<fo:block
font-size="inherit"
start-indent="0in">
<fo:inline
border-left-width="0pt"
border-right-width="0pt">
<fo:inline
border-left-width="0pt"
border-right-width="0pt">bookmeta/shortdesc<fo:inline
baseline-shift="20%"
font-size="75%"
line-height-shift-adjustment="disregard-shifts"><fo:inline
line-height="100%"
font-family="Helvetica, Arial Unicode MS"
baseline-shift="20%"
font-size="smaller">®</fo:inline>
</fo:inline>
</fo:inline> test</fo:inline>
</fo:block>
</fo:marker>
<fo:block
font-size="10pt"
id="d2e394"
space-after="0.25in"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:marker
marker-class-name="current-chapter-number">6</fo:marker>
<fo:marker
marker-class-name="bookmap-partno"/>
<fo:table
table-layout="fixed">
<fo:table-column
column-width="0.75in"/>
<fo:table-column/>
<fo:table-body>
<fo:table-row>
<fo:table-cell
display-align="after">
<fo:block
border-bottom="3pt solid black"
border-bottom-style="solid"
border-bottom-width="2pt"
border-top-style="none"
border-top-width="2pt"
break-before="auto"
font-size="18pt"
font-weight="bold"
keep-with-next.within-column="always"
padding-top="10pt"
space-after="16.8pt"
space-before="0pt"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">
<fo:inline
id="_OPENTOPIC_TOC_PROCESSING_d80e3474">
<fo:inline
border-bottom-style="none"
border-bottom-width="2pt"
border-top-style="none"
border-top-width="2pt"
font-size="20pt"
font-weight="bold"
padding-top="10pt">
<fo:marker
marker-class-name="chapter-for-fig">6</fo:marker>
<fo:inline
font-size="36pt"
font-weight="bold"
padding-right="0.485in">6</fo:inline>
</fo:inline>
</fo:inline>
</fo:block>
</fo:table-cell>
<fo:table-cell
display-align="after">
<fo:block
border-bottom="3pt solid black"
border-bottom-style="solid"
border-bottom-width="2pt"
border-top-style="none"
border-top-width="2pt"
break-before="auto"
font-size="18pt"
font-weight="bold"
keep-with-next.within-column="always"
padding-top="10pt"
space-after="16.8pt"
space-before="0pt"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">test</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:block-container
margin-left="0.75in"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
And here's the equivalent using the default PDF2 styles:
<fo:page-sequence
force-page-count="even"
master-reference="body-sequence">
<fo:static-content
flow-name="xsl-footnote-separator">
<fo:block>
<fo:leader
color="black"
leader-length="25%"
leader-pattern="rule"
rule-style="solid"
rule-thickness="0.5pt"/>
</fo:block>
</fo:static-content>
<fo:static-content
flow-name="odd-body-footer">
<fo:block
end-indent="10pt"
space-after="10pt"
space-after.conditionality="retain"
text-align="end"/>
</fo:static-content>
<fo:static-content
flow-name="odd-body-header">
<fo:block
end-indent="10pt"
space-before="10pt"
space-before.conditionality="retain"
text-align="end"> | <fo:inline><fo:retrieve-marker
retrieve-class-name="current-header"/>
</fo:inline> | <fo:inline
font-weight="bold"><fo:page-number/>
</fo:inline>
</fo:block>
</fo:static-content>
<fo:static-content
flow-name="first-body-header">
<fo:block
end-indent="10pt"
space-before="10pt"
space-before.conditionality="retain"
text-align="end"/>
</fo:static-content>
<fo:static-content
flow-name="first-body-footer">
<fo:block
end-indent="10pt"
space-after="10pt"
space-after.conditionality="retain"
text-align="end"/>
</fo:static-content>
<fo:static-content
flow-name="last-body-header">
<fo:block/>
</fo:static-content>
<fo:static-content
flow-name="last-body-footer">
<fo:block/>
</fo:static-content>
<fo:flow
flow-name="xsl-region-body">
<fo:block
font-size="10pt"
id="d2e394">
<fo:marker
marker-class-name="current-topic-number">6</fo:marker>
<fo:marker
marker-class-name="current-header">test</fo:marker>
<fo:block
id="_OPENTOPIC_TOC_PROCESSING_d61e3474">
<fo:block
border-bottom-style="solid"
border-bottom-width="2pt"
border-top-style="solid"
border-top-width="2pt"
font-size="20pt"
font-weight="bold"
padding-top="10pt">Chapter <fo:block
font-size="40pt"
font-weight="bold">6</fo:block>
</fo:block>
</fo:block>
<fo:block
border-bottom="3pt solid black"
font-size="18pt"
font-weight="bold"
keep-with-next.within-column="always"
padding-top="16.8pt"
space-after="16.8pt"
space-before="0pt"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS">test</fo:block>
<fo:table
page-break-after="always"
table-layout="fixed"
width="100%">
<fo:table-column
column-number="1"
column-width="35%"/>
<fo:table-column
column-number="2"
column-width="65%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block
end-indent="5pt"
font-size="10.5pt"
line-height-shift-adjustment="disregard-shifts"
font-family="Helvetica, Arial Unicode MS"/>
</fo:table-cell>
<fo:table-cell
border-left-color="black"
border-left-style="solid"
border-left-width="1pt"
padding-left="10pt">
<fo:block/>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
My styles are so radically different, I'm having difficulties isolating where to start on troubleshooting this issue. Any guidance is appreciated.

I believe the problem lies with the <fo:block-container /> at the very end of your code. It requires a <block> child (and doesn't serve much purpose without it anyway).
Try commenting out that element and see how the transform runs.
If that works (and you still need the <fo:block-container />) add an empty <block> as a child so it's valid even without any child topics.

Related

format month of grouped news items in Typo3

I have news items, grouped by year and month. Here the code:
<f:groupedFor each="{paginatedNews}" as="groupedNews1" groupBy="yearOfDatetime" groupKey="year">
<f:groupedFor each="{groupedNews1}" as="groupedNews" groupBy="monthOfDatetime" groupKey="month">
<div style="border:1px solid blue;padding:10px;margin:10px;">
<h1>{month} {year} </h1>
<f:for each="{groupedNews}" as="newsItem">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</div>
</f:groupedFor>
</f:groupedFor>
Unfortunately, month and year are displayed in numbers in frontend, e.g.
03 2019
..(some news items)
02 2019
...
01 2019
However, what I need is this:
March 2019
...
February 2019
...
January 2019
How can I achieve this?
On the original EXT:news this method has been used:
Look at the template EXT:news/Resources/Private/Templates/News/DateMenu.html
<f:translate key="month.{month}" />
on the EXT:news/Resources/Private/Language/locallang.xlf you will find:
<trans-unit id="month.01" xml:space="preserve">
<source>January</source>
</trans-unit>
And so forth.

Update the counter by +1 when another record with two similar values exists in xslt 2.0

I have the below xml:
<EmployeeLeaveDataUpsertRequest>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>136</Hours>
<Date_from_ec>20170401</Date_from_ec>
<Date_to_ec>20170429</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
<Row>
<Emp_id>12</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0900</Pay_comp>
<Hours>40</Hours>
<Date_from_ec>20170206</Date_from_ec>
<Date_to_ec>20170210</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>8</Hours>
<Date_from_ec>20170111</Date_from_ec>
<Date_to_ec>20170115</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
In the above xml you can see that every record has an element counter with default value set as 1.
In an event for same Emp_id and Pay_comp then I need to set the counter as 1 for first record , 2 for second record and so on.
Like in the above xml you can see two records where the Emp_id is 11 and Pay_comp is AU_0299 -- so for the first one set the counter as 1 and for the next one a 2.
output xml:
<EmployeeLeaveDataUpsertRequest>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>136</Hours>
<Date_from_ec>20170401</Date_from_ec>
<Date_to_ec>20170429</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
<Row>
<Emp_id>11</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0299</Pay_comp>
<Hours>8</Hours>
<Date_from_ec>20170111</Date_from_ec>
<Date_to_ec>20170115</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>2</Counter>
</Row>
<Row>
<Emp_id>12</Emp_id>
<Pay_slip_no>1</Pay_slip_no>
<Pay_comp>AU_0900</Pay_comp>
<Hours>40</Hours>
<Date_from_ec>20170206</Date_from_ec>
<Date_to_ec>20170210</Date_to_ec>
<Date_ped> </Date_ped>
<No_of_period>1</No_of_period>
<Ma_ind>M</Ma_ind>
<Fa_ind>N</Fa_ind>
<Counter>1</Counter>
</Row>
I have tried for loop but couldn't succeed. Need your inputs on the XSLT code which could achieve it
You could use a key to identify duplicates, with XSLT 3.0 (as now supported by Saxon 9.8 or current versions of Altova XMLSpy and Raptor) it is as easy as:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
expand-text="yes"
version="3.0">
<xsl:key name="group" match="Row" use="Emp_id , Pay_comp" composite="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="Row[not(. is key('group', (Emp_id , Pay_comp))[1])]/Counter">
<xsl:copy>{index-of(key('group', (../Emp_id , ../Pay_comp)), ..)}</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With XSLT 2.0 you can translate the above to
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="2.0">
<xsl:key name="group" match="Row" use="concat(Emp_id, '|', Pay_comp)"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Row[not(. is key('group', concat(Emp_id, '|', Pay_comp))[1])]/Counter">
<xsl:copy>
<xsl:value-of select="index-of(key('group', concat(../Emp_id, '|', ../Pay_comp)), ..)"/>
</xsl:copy>
</xsl:template>

How to find all numbers in a string with XSLT 1

There are some nice solutions to How to find all numbers in a string for XSLT 2 and even 3. How can I accomplish the exact same thing within the limits of XSLT 1 (withe the possible help of EXSLT)?
Here’s an example:
<data>
<sig>NL Mellin 1-1 36</sig>
<sig>NL Mellin 1-1 38</sig>
<sig>NL Mellin 1-10 02</sig>
<sig>NL Mellin 1-10 04</sig>
<sig>NL Mellin 1-10 09</sig>
</data>
The desired output would be:
1 1 36
1 1 38
1 10 02
1 10 04
1 10 09
Try it this way:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="/">
<xsl:for-each select="data/sig">
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="translate(., '-', ' ')"/>
</xsl:call-template>
<xsl:if test="position()!=last()">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="text"/>
<xsl:param name="delimiter" select="' '"/>
<xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
<xsl:if test="$token = translate($token, translate($token, '0123456789', ''), '')">
<xsl:value-of select="$token"/>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:if test="contains($text, $delimiter)">
<!-- recursive call -->
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Note:
If you have multiple delimiters, you need to translate them to a common character (space in my example);
I didn't bother to remove the trailing space in each line;
If your processor supports the EXSLT str:tokenize() function, this could be simpler.

Defining time dimension in Mondrain Schema?

I am trying to define time dimension in Mondrian schema. In Mondrian time dimension it require 3 level-type must be Years, Quarters, Months.
But my table contain only one date field. So how it is possible?
Can I use postgreSQL query in Mondrian? So I can use 3 query to select Years, Quarters and Month from single date field.
Create simple table with only one date column:
create table tmp_cube as (select generate_series('2011-01-01'::date, '2012-01-01'::date, '1 day')::date gs);
Create dummy cube:
<Schema name="New Schema1">
<Cube name="Test" visible="true" cache="true" enabled="true">
<Table name="tmp_cube" schema="public" alias="">
</Table>
<Dimension type="TimeDimension" visible="true" foreignKey="gs" name="Time Dimension">
<Hierarchy name="New Hierarchy 0" visible="true" hasAll="true" primaryKey="gs">
<View alias="test_view">
<SQL dialect="generic">SELECT gs, extract(year from gs) as year, extract(quarter from gs) as quarter, extract(month from gs) as month FROM tmp_cube</SQL>
</View>
<Level name="Year" visible="true" column="year" type="Integer" internalType="int" uniqueMembers="false" levelType="TimeYears">
</Level>
<Level name="Quarter" visible="true" column="quarter" type="Integer" uniqueMembers="false" levelType="TimeQuarters">
</Level>
<Level name="Month" visible="true" column="month" type="Integer" uniqueMembers="false" levelType="TimeMonths">
</Level>
</Hierarchy>
</Dimension>
<Measure name="Count Rows" column="gs" aggregator="count" visible="true">
</Measure>
</Cube>
</Schema>
Now I see in Saiku:

XSLT add new node outside of current node

I'm trying to add a new element based on a date comparison. If the parent DATE is within the last 7 days, I want to add a new element. I wrote the code to do the date comparison but I'm having a hard time figuring out where to put it. Currently, it is in the template that reformats the parent DATE but this results in my new element inside the date element. Is there a way to create a new element outside of the current element? Thanks.
My Input
<?xml version="1.0" encoding="UTF-8"?>
<NOTICES>
<PRESOL>
<DATE>03012013</DATE>
<AGENCY><![CDATA[Department of the Interior]]></AGENCY>
<OFFICE><![CDATA[Fish and Wildlife Service]]></OFFICE>
<LOCATION><![CDATA[CGS-WO]]></LOCATION>
<ZIP>97232</ZIP>
<CHANGES>
<MOD>
<DATE>01112013</DATE>
<COUNTRY>US</COUNTRY>
</MOD>
</CHANGES>
</PRESOL>
<COMBINE>
<DATE>03012013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Air Force Materiel Command]]></OFFICE>
<LOCATION><![CDATA[Tinker OC-ALC - (Central Contracting)]]></LOCATION>
<ZIP>73145-3015</ZIP>
</COMBINE>
<COMBINE>
<DATE>03052013</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Military Sealift Command]]></OFFICE>
<LOCATION><![CDATA[MSC Norfolk]]></LOCATION>
</COMBINE>
<COMBINE>
<DATE>03292013</DATE>
<AGENCY><![CDATA[Department of Veterans Affairs]]></AGENCY>
<OFFICE><![CDATA[Grand Junction VAMC)]]></OFFICE>
<LOCATION><![CDATA[Veterans Affairs Medical Center]]></LOCATION>
</COMBINE>
<PRESOL>
<DATE>03302013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
<CHANGES>
<MOD>
<DATE>01112013</DATE>
<COUNTRY>US</COUNTRY>
</MOD>
<MOD>
<DATE>01112013</DATE>
<COUNTRY>UK</COUNTRY>
</MOD>
<MOD>
<DATE>01142013</DATE>
<COUNTRY>JAPAN</COUNTRY>
</MOD>
</CHANGES>
</PRESOL>
<FAIROPP>
<DATE>04012013</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Bureau of Medicine and Surgery]]></OFFICE>
<LOCATION><![CDATA[NH Camp Pendleton]]></LOCATION>
<ZIP>92055</ZIP>
<CHANGES>
<MOD>
<DATE>02122011</DATE>
<COUNTRY>JAPAN</COUNTRY>
</MOD>
</CHANGES>
</FAIROPP>
</NOTICES>
Desired Output:
<?xml version="1.0" encoding="UTF-8"?>
<NOTICES>
<PRESOL>
<DATE>03012013</DATE>
<AGENCY><![CDATA[Department of the Interior]]></AGENCY>
<OFFICE><![CDATA[Fish and Wildlife Service]]></OFFICE>
<LOCATION><![CDATA[CGS-WO]]></LOCATION>
<ZIP>97232</ZIP>
<CHANGES>
<MOD>
<DATE>01112013</DATE>
<COUNTRY>US</COUNTRY>
</MOD>
</CHANGES>
</PRESOL>
<COMBINE>
<DATE>03012013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Air Force Materiel Command]]></OFFICE>
<LOCATION><![CDATA[Tinker OC-ALC - (Central Contracting)]]></LOCATION>
<ZIP>73145-3015</ZIP>
</COMBINE>
<COMBINE>
<DATE>03052013</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Military Sealift Command]]></OFFICE>
<LOCATION><![CDATA[MSC Norfolk]]></LOCATION>
</COMBINE>
<COMBINE>
<DATE>03292013</DATE>
**<mostrecent>YES</mostrecent>**
<AGENCY><![CDATA[Department of Veterans Affairs]]></AGENCY>
<OFFICE><![CDATA[Grand Junction VAMC)]]></OFFICE>
<LOCATION><![CDATA[Veterans Affairs Medical Center]]></LOCATION>
</COMBINE>
<PRESOL>
<DATE>03302013</DATE>
**<mostrecent>YES</mostrecent>**
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
<CHANGES>
<MOD>
<DATE>01112013</DATE>
<COUNTRY>US</COUNTRY>
</MOD>
<MOD>
<DATE>01112013</DATE>
<COUNTRY>UK</COUNTRY>
</MOD>
<MOD>
<DATE>01142013</DATE>
<COUNTRY>JAPAN</COUNTRY>
</MOD>
</CHANGES>
</PRESOL>
<FAIROPP>
<DATE>04012013</DATE>
**<mostrecent>YES</mostrecent>**
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Bureau of Medicine and Surgery]]></OFFICE>
<LOCATION><![CDATA[NH Camp Pendleton]]></LOCATION>
<ZIP>92055</ZIP>
<CHANGES>
<MOD>
<DATE>02122011</DATE>
<COUNTRY>JAPAN</COUNTRY>
</MOD>
</CHANGES>
</FAIROPP>
</NOTICES>
My XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output omit-xml-declaration="yes" indent="yes" cdata-section-elements="AGENCY DESC CLASSCOD CONTACT DATE NAICS LINK OFFADD OFFICE SUBJECT ZIP AGENCY ZIP"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="backdate1" select="current-date() -7*xs:dayTimeDuration('P1D')"/>
<xsl:variable name="backdate" select="xs:date(substring($backdate1, 1, 10))"/>
<!-- copy all nodes -->
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="DATE/text()">
<!-- format DATE mm/dd/yyyy -->
<xsl:value-of select="concat(substring(., 1, 2), '/', substring(., 3, 2), '/', substring(., 5, 4))"/>
**<!-- add new node mostrecent if date is within the last 7 days -->
<xsl:variable name="subtract_date" select="days-from-duration(xs:date(concat(substring(., 5, 4), '-', substring(., 1, 2), '-', substring(., 3, 2))) - xs:date(substring($backdate1, 1, 10)))"/>
<xsl:if test="$subtract_date >= 0">
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:text disable-output-escaping="yes">mostrecent</xsl:text>
<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:text disable-output-escaping="yes"></</xsl:text>
<xsl:text disable-output-escaping="yes">mostrecent</xsl:text>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:if>**
</xsl:template>
<!-- keep only the parent date node and delete all children date nodes -->
<xsl:template match="DATE[../ancestor::*/DATE]"/>
<!-- add new node type to each child node -->
<xsl:template match="NOTICES/child::node()">
<xsl:text disable-output-escaping="yes"><</xsl:text><xsl:value-of select="name(.)"/><xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:apply-templates select="#*|node()"/>
<type>
<xsl:value-of select ="name(.)"/>
</type>
<xsl:text disable-output-escaping="yes"></</xsl:text><xsl:value-of select="name(.)"/><xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:template>
</xsl:stylesheet>
You can do this if you match on the DATE element instead of its text node:
<xsl:template match="DATE">
<xsl:variable name="dStr" select="string(.)" />
<xsl:variable name="bdStr" select="string($backdate1)" />
<!-- format DATE mm/dd/yyyy -->
<xsl:copy>
<xsl:value-of select="concat(substring($dStr, 1, 2), '/',
substring($dStr, 3, 2), '/',
substring($dStr, 5, 4))"/>
</xsl:copy>
<!-- add new node mostrecent if date is within the last 7 days -->
<xsl:variable name="subtract_date"
select="days-from-duration(xs:date(
concat(substring($dStr, 5, 4), '-',
substring($dStr, 1, 2), '-',
substring($dStr, 3, 2))) -
xs:date(substring($bdStr, 1, 10)))"/>
<xsl:if test="$subtract_date >= 0">
<mostrecent>YES</mostrecent>
</xsl:if>
</xsl:template>