I'm trying to reorder the attributes of a tag using the Serialization parameter "saxon:attribute-order" but I could not make it works, what am I missing?
Source file:
<?xml version="1.0"?>
<list>
<span class="pagebreak" name="1" title="ONE">Test</span>
<span class="nobreak" name="X" title="X">Test</span>
<span class="pagebreak" name="2" title="TWO">Test</span>
<span class="pagebreak" name="3" title="THREE">Test</span>
<span class="pagebreak" name="4" title="FOUR">Test</span>
<span class="nobreak" name="Y" title="Y">Test</span>
<span class="pagebreak" name="5" title="FIVE">Test</span>
</list>
XSL:
<?xml version="1.0"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/"
exclude-result-prefixes="saxon">
<xsl:output method="xml" indent="yes" saxon:attribute-order="title name class * xml:space"/>
<xsl:template match="/">
<xsl:apply-templates select="*/span[contains(#class, 'pagebreak')]" />
</xsl:template>
<xsl:template match="*/span[contains(#class, 'pagebreak')]">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
Output File:
<?xml version="1.0" encoding="UTF-8"?>
<span class="pagebreak" name="1" title="ONE">Test</span>
<span class="pagebreak" name="2" title="TWO">Test</span>
<span class="pagebreak" name="3" title="THREE">Test</span>
<span class="pagebreak" name="4" title="FOUR">Test</span>
<span class="pagebreak" name="5" title="FIVE">Test</span>
There's nothing wrong with the code you've shown us, so the problem is somewhere in what you haven't shown us...
Perhaps you're using Saxon-HE which doesn't recognise extension attributes.
Perhaps you're sending the output to a destination other than a serializer?
Try it from the command line, with the -t option, and see if that works, and then we can take it from there.
Related
I'm trying to strip all tags from a xml doc and i need to strip all text from a specific node only. For more clearity see the below example:
<root>
<p>My 1st Semester Visual</p>
<p>
<b>Self Reflection</b>
</p>
<p>The activity</p>
<content-block>
<div class="imageWrapper" />
</content-block>
<p id="5fce699db97470099ea6c7e6"> </p>
<content-block>
<div class="carousel">
<div class="carouselHeader" />
<div class="carouselNavbar">
<div class="carouselNavbarThumbnails" />
</div>
</div>
My Space Unit Flyer
</content-block>
<div>
<br />
</div>
</root>
Result:
<root><text>My 1st Semester VisualSelf ReflectionThe activity
My Space Unit Flyer
</text><contentBlocks>2</contentBlocks></root>
Expected result: I also need to remove text that is inside the <content-block>.
<root><text>My 1st Semester VisualSelf ReflectionThe activity
</text><contentBlocks>2</contentBlocks></root>
My xslt:
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>
<!-- Strip out white space -->
<xsl:strip-space elements="*"/>
<!-- Strip out all html tags, only leaving text contents -->
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="root">
<root>
<text>
<xsl:apply-templates/>
</text>
<contentBlocks>
<xsl:if test="//content-block">
<xsl:value-of select="count(//content-block)"/>
</xsl:if>
<xsl:if test="figure">
<xsl:value-of select="count(figure)"/>
</xsl:if>
</contentBlocks>
</root>
</xsl:template>
</xsl:transform>
Thanks in advance
<!-- Add this to your code. It suppresses content-block. -->
<xsl:template match="content-block"/>
THIS IS MY xsl after Title I need to display VacancyID from below xml can you any help me how to get this value
unable to access atom-field in xsl
need help to fix this
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>abc</title>
<link>https://google.com</link>
<description>test</description>
<item>
<link>https://google.com</link>
<title>abc</title>
<a10:updated>2016-06-22T10:44:49Z</a10:updated>
<a10:content type="text/xml">
<Vacancy>
<VacancyID>123</VacancyID>
</Vacancy>
</a10:content>
</item>
</channel>
</rss>
xsl:
THIS IS MY xsl after Title i need to display VacancyID from ablove xml can you any help me how to get this valu
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<div id="press-release">
<xsl:apply-templates select="rss/channel/item"/>
</div>
</xsl:template>
<xsl:template match="item">
<div class="press-item">
<a href="{./link}" target="_blank" class="title" title="{./title}">
<xsl:value-of select="./title" disable-output-escaping="yes" />
vacancyID????????????(need heleher)
</a>
<xsl:template match="atom:content">
From within your template matching item, you can use:
<xsl:value-of select="atom:content/Vacancy/VacancyID" />
to get the value of VacancyID.
First, my code is..
<?xml version="1.0" encoding="UTF-8"?>
<mpml>
<problem>
<context>
<p>두 다항식 $A=x^2 - xy + 2y^2$, $B=3x^2 + 2xy - y^2$에 대하여 $A-B$를 계산한 식이 $ax^2 +bxy + cy^2$일 때, 상수 $a+b+c$의 값은?</p>
</context>
<answerlist>
<i>-4</i>
<i>-2</i>
<i>0</i>
<i>2</i>
<i>4</i>
</answerlist>
</problem>
<problem>
<context>
<p>연립방정식 $\begin{cases} x+y+z=30 \\ 2x+3y+4z=93 \\ y=z+3 \end{cases}$의 해를 $x=a$, $y=b$, $z=c$라 할 때, $a-2b+3c$의 값은? (단, $a$, $b$, $c$는 실수.)</p>
</context>
<answerlist>
<i>7</i>
<i>9</i>
<i>11</i>
<i>13</i>
<i>15</i>
</answerlist>
</problem>
</mpml>
and it's xsl code is..
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h2> Testing.. </h2>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="problem">
<div class="problem">
<xsl:apply-templates select="context"/>
<xsl:apply-templates select="answerlist"/>
</div>
</xsl:template>
<xsl:template match="context">
<div class="context">
</div>
</xsl:template>
<xsl:template match="answerlist">
<div class="answerlist">
test answerlist
</div>
</xsl:template>
</xsl:transform>
In XSLT Tryit editor (thanks to w3school), above XSLT work as I expected. However when I tried this in my server, there is an 'extra content at the end of the document.' error and nothings shown except very first template.
I think the problem is that your XSLT does not produce well-formed XML in output: in the template <xsl:template match="/">, you should wrap content within a single root tag.
E.g.:
<xsl:template match="/">
<body>
<h2> Testing.. </h2>
<xsl:apply-templates/>
</body>
</xsl:template>
I am given XML as input that I have no control over the structure. I need to break the XML up into parts and process each part separately. Below is a very simplified version of a file that I would process.
I am trying to use the grouping functionality of XSLT 2.0 to break up this XML by using the <breakEle> tag as the part boundaries. The <breakEle> can appear at any level too. Is what I'm trying to do even possible with XSLT 2.0? I have been successful in accomplishing this with XSLT 1.0 using Muenchian grouping but I want to get away from that if we can.
Sample input:
<item class="poem">
<div>
<div>
<p>paragraph 1</p>
<breakEle groupNum="1"/>
</div>
<div>
<p>Paragraph in another div.</p>
</div>
<breakEle groupNum="2"/>
<div>
<div>
<h4>header</h4>
<p>1st line</p>
<p>2nd line</p>
<br/>
<p>3rd line</p>
<p>4th line</p>
<page n="100"/>
<p>5th line</p>
</div>
<breakEle groupNum="3"/>
</div>
</div>
</item>
What I'm trying to work with:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:template match="/">
<newRoot>
<xsl:copy>
<xsl:for-each-group select="*" group-ending-with="breakEle">
<div num="{#groupNum}">
<xsl:copy-of select="current-group()"/>
</div>
</xsl:for-each-group>
</xsl:copy>
</newRoot>
</xsl:template>
</xsl:stylesheet>
Would like to end up with something like this:
<newRoot>
<div num="1">
<p>paragraph 1</p>
</div>
<div num="2">
<p>Paragraph in another div.</p>
</div>
<div num="3">
<h4>header</h4>
<p>1st line</p>
<p>2nd line</p>
<br/>
<p>3rd line</p>
<p>4th line</p>
<page n="100"/>
<p>5th line</p>
</div>
</newRoot>
The following stylesheet returns the expected result when applied to the given example.
It works under the assumption that each group should only contain leaf elements.
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/item">
<newRoot>
<xsl:for-each-group select=".//*[not(*)]" group-ending-with="breakEle">
<div num="{current-group()[last()]/#groupNum}">
<xsl:copy-of select="current-group()[not(self::breakEle)]"/>
</div>
</xsl:for-each-group>
</newRoot>
</xsl:template>
</xsl:stylesheet>
xml code
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="MyXmlTransformer.xsl"?>
<JMO_obsList xmlns="urn:metoc:jmcbl:jmibl">
<urn:JMO_obs urn:observationTime ="20110118150000" urn:platformID="A001" urn:reporTypeCode="AUTO"
urn:HorizontalDatum="WGE" urn:verticalDatum="MSL" urn:stationMode="0"
urn:networkType="PTDS" xmlns:urn="urn:metoc:jmcbl:jmcbl:jmibl">
<JMO_surfaceObs urn:stationPressure ="998.308" urn:airTemperature="28.56"
urn:windDirection="320" urn:windSpeed="3.807"/>
<urn:JMO_precipitation urn:PrecipAmount="6.858" urn:observationPeriod="60"
urn:precipType="L" urn:occcurenceID="1"/>
</urn:JMO_obs>
</JMO_obsList>
xslt code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="/">
<html>
<body>
<b>METAR</b>
<br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_surfaceObs/windSpeed"/>
</span><br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_surfaceObs/stationPressure"/>
</span><br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_Obs/observationTime"/>
</span><br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_precipitation/PrecipAmount"/>
</span><br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
In your stylesheet you will have to define prefixes for the namespace "urn:metoc:jmcbl:jmibl" and urn:metoc:jmcbl:jmcbl:jmibl and use them to explicitly qualify the references to JMO_obsList and other elements. Furthermore, the references to windSpeed and other XML attributes need to be referenced with the attribute: axis
An example of a complete value-of declaration:
<span style="color:blue">
<xsl:value-of xmlns:ns1="urn:metoc:jmcbl:jmibl"
xmlns:ns2="urn:metoc:jmcbl:jmcbl:jmibl"
select="ns1:JMO_obsList/ns2:JMO_obs/ns1:JMO_surfaceObs/#ns2:stationPressure"/>
</span>