Hello!
I tried to transform the attached XML with the attached XSL.
This is the Java source:
final TransformerFactory trf = TransformerFactory.newInstance();
final Transformer tr = trf.newTransformer(new
StreamSource(_formxsl.getInputStream()));
tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
tr.setOutputProperty(OutputKeys.INDENT, "no");
StringWriter writer = new StringWriter();
final StreamResult result = new StreamResult(writer);
tr.transform(new StreamSource(_formxml.getInputStream()), result);
writer.flush();
writer.toString();
_formxsl and _formxml are both Resource, they are attached to this message.
The transform result by
http://xslt.online-toolz.com/tools/xslt-transformation.php (*AND*
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog)
looks like this:
<?xml version="1.0"?>
<ros:relobjects
xmlns:ros="urn://x-artefacts-vs-it-ru/p321/schema/relobjects/1.0"
xmlns:bo="urn://x-artefacts-it-ru/p321/Application/1.0"
xmlns:fo="urn://x-artefacts-it-ru/p321/Step2Form/1.0"
xmlns:ct="urn://x-artefacts-it-ru/p321/ComplexTypes/1.0"
xmlns:st="urn://x-artefacts-it-ru/p321/SimpleTypes/1.0"
xmlns:da="urn://x-artefacts-it-ru/dob/document-attachment/1.1"><ros:RO
type="VEHICLE_OWNER_DRIVER" id="5672f6f9-176e-42cb-ae76-de1973a77bde">
<ros:BO role="VEHICLE"/>
<ros:BO role="OWNER"/>
<ros:BO role="DRIVER">76bd59e9-166c-4a22-9e6b-b196849be358</ros:BO>
<ros:BO role="DRIVER">5fb19f85-0617-4782-9a4f-fdc2a60c5e64</ros:BO>
<ros:BO role="DRIVER">f39bafdc-7fab-472d-965e-398e87a1472a</ros:BO>
</ros:RO></ros:relobjects>
But the result produced by Java is merely this:
<ros:relobjects
xmlns:ros="urn://x-artefacts-vs-it-ru/p321/schema/relobjects/1.0"
xmlns:da="urn://x-artefacts-it-ru/dob/document-attachment/1.1"
xmlns:st="urn://x-artefacts-it-ru/p321/SimpleTypes/1.0"
xmlns:ct="urn://x-artefacts-it-ru/p321/ComplexTypes/1.0"
xmlns:fo="urn://x-artefacts-it-ru/p321/Step2Form/1.0"
xmlns:bo="urn://x-artefacts-it-ru/p321/Application/1.0"><ros:RO
type="VEHICLE_OWNER_DRIVER"
id="5672f6f9-176e-42cb-ae76-de1973a77bde"/></ros:relobjects>
*- i.e. no BO elements at all.*
Why does this happen? Is there some mistake or undefined behavior in my
stylesheet?
Thank you!
Maksim
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ros="urn://x-artefacts-vs-it-ru/p321/schema/relobjects/1.0"
xmlns:bo="urn://x-artefacts-it-ru/p321/Application/1.0"
xmlns:fo="urn://x-artefacts-it-ru/p321/Step2Form/1.0"
xmlns:ct="urn://x-artefacts-it-ru/p321/ComplexTypes/1.0"
xmlns:st="urn://x-artefacts-it-ru/p321/SimpleTypes/1.0"
xmlns:da="urn://x-artefacts-it-ru/dob/document-attachment/1.1">
<xsl:template match="/fo:Step2Form/fo:vdo">
<ros:relobjects>
<!-- В нашем примере только одна вложенная сущность -->
<ros:RO type="VEHICLE_OWNER_DRIVER"> <!--id должен приехать из формы. надо решить, где он там будет-->
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:apply-templates/>
</ros:RO>
</ros:relobjects>
</xsl:template>
<xsl:template match="/fo:Step2Form/fo:vdo/fo:Vehicle">
<!--Тут имя элемента должно совпадать с названием роли-->
<ros:BO role="VEHICLE"><xsl:value-of select="fo:guid"/></ros:BO>
</xsl:template>
<xsl:template match="/fo:Step2Form/fo:vdo/fo:Owner">
<ros:BO role="OWNER"><xsl:value-of select="fo:guid"/></ros:BO>
</xsl:template>
<xsl:template match="/fo:Step2Form/fo:vdo/fo:Driver">
<ros:BO role="DRIVER"><xsl:value-of select="fo:guid"/></ros:BO>
</xsl:template>
<xsl:template match="/fo:Step2Form/fo:vdo/*">
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<ns24:Step2Form xmlns:ns3="urn://x-artefacts-it-ru/dob/document-attachment/1.1" xmlns:ns20="urn://x-artefacts-it-ru/p321/ComplexTypes/1.0" xmlns:ns24="urn://x-artefacts-it-ru/p321/Step2Form/1.0">
<ns24:vdo id="5672f6f9-176e-42cb-ae76-de1973a77bde">
<ns24:Vehicle>
<ns24:guid></ns24:guid>
</ns24:Vehicle>
<ns24:Owner>
<ns24:guid></ns24:guid>
</ns24:Owner>
<ns24:Driver>
<ns24:guid>76bd59e9-166c-4a22-9e6b-b196849be358</ns24:guid>
<ns24:driverName>xxr</ns24:driverName>
</ns24:Driver>
<ns24:Driver>
<ns24:guid>5fb19f85-0617-4782-9a4f-fdc2a60c5e64</ns24:guid>
<ns24:driverName></ns24:driverName>
</ns24:Driver>
<ns24:Driver>
<ns24:guid>f39bafdc-7fab-472d-965e-398e87a1472a</ns24:guid>
<ns24:driverName></ns24:driverName>
</ns24:Driver>
<ns24:relOwnString>âàïàâïâàï</ns24:relOwnString>
</ns24:vdo>
</ns24:Step2Form>